Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • jQuery Text()

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 277
    Comment on it

    This method is used to set the content of selected elements even we can get the text content also .When this method is return the text content ,it returns the all matched elements without the HTML markup. And when this method is used to set the content , it overwrites the content of all the matched elements.
    Syntax :

    $(selelctor).text( )
    

    Syntax for set text :

    $(selector).text(content)
    

    Syntax for set text using function :

    $(selector).text(function(index,currentcontent))
    

    Example :
    HTML Code :

    <html>
    <head></head>
    <body>
    <p>It will <b>change<b> after click on button</p>
    <p></p> // In this Same content will come after execution this code( content is ->It will change after click on button i.e color will be red)
    </body>
    </html>
    

    jQuery Code :

     var a = $("p:first").text();
        $("p:last").html(a)
    

    CSS Code :

    p{
    color : red ;
    }
    b{
    color : blue ;
    }
    

    Output :

    It will change after click on button // in this "It will" content color will change i.e red and rest of the is blue
    It will change after click on button // This content inserted after jQuery code executed in p tag
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: