Get a free trial // Grow your CSS skills // Land your dream job

jQuery – How to find what the text is inside an element.

  • # October 10, 2008 at 1:04 pm

    I was trying to figure out how to get the text off a page in a <TD> with a Class. That way I can do a conditional statement on the return value such as either hide or show another DIV.

    I tried the following with no luck:


    var giftopt = jQuery(“#giftopt”);

    if (“#giftopt == ‘Someone Else'”) {
    //do something
    if (“#giftopt == ‘Me'”) {
    //do something

    # October 10, 2008 at 2:06 pm

    You use the .text() function to get the text out of an element

    var testText = $(“td#giftopt”).text();
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed