Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery Selector for Element type and Class name?

I have an element we'll call selectedTable that contains this innerHtml:

<TBODY>
    <TR>
        <TD></TD>
        <TD></TD>
        <TD class='ms-cal-nav-buttonsltr'></TD>
    </TR>
</TBODY>

I'm trying to use JQuery selectors to return the <TD> tag with the "ms-cal-nav-buttonsltr" class. I've found that $(selectedTable).find("TD") returns all the TD tags in the table as expected, but I'm wondering how I might go about combining the TD element selector with a class selector. I've tried $(subnode).find("TD").find(".ms-cal-nav-buttonsltr") and $(subnode).find("TD .ms-cal-nav-buttonsltr") to no avail, but those were just shots in the dark. What's the most efficient way to accomplish this? Thanks in advance.

like image 320
Ocelot20 Avatar asked Aug 24 '11 17:08

Ocelot20


People also ask

How can I select an element by class with jQuery?

$( "#myDivId" ); This code selects an element with a class of "myCssClass". Since any number of elements can have the same class, this expression will select any number of elements. var myValue = $( "#myDivId" ).

How do you select an element with ID and class?

CSS ID will override CSS Class properties. To select an element with a specific id, write a hash (#) character, followed by the id of the element.

How do you select an element with the class name?

class selector selects elements with a specific class attribute. To select elements with a specific class, write a period (.) character, followed by the name of the class.


1 Answers

Just concatenate the two:

$(selectedTable).find("td.ms-cal-nav-buttonsltr");

the selectors you tried were looking for a .ms-cal-nav-buttonsltr element underneath the td.

like image 181
Dennis Avatar answered Oct 13 '22 09:10

Dennis