开发者

How to select a row with particular class name in JQuery

I have a table as follows

<table>
    <tr>
        <td id="start">Starting Point<input type="button" value="start the test" onclick="get_the_next()" /></td>
    </tr>
    <tr>
        <td>not the right class - skip me</td>
    </tr>
    <tr class="concept1">
        <td>get me if you can!</td>
    </tr>开发者_开发问答;
    <tr class="concept2">
        <td>but not me, I'm not the next</td>
    </tr>
    <tr>
        <td>not the right class - skip me</td>
    </tr>
</table>

I need to select row with class name "concept2". How can I do that in JQuery?


jQuery(function($) {
    var row = $('.concept2');
});

To explain, the jQuery(function($) { ... }); attaches the callback (ie the "function") to the DOM Ready event. This ensures your code only runs after the entire document had loaded.

The $('.concept2') uses jQuery's CSS style selectors. In this case, it is using the class selector.

Update

To answer your comment, check out the manipulation category. An example might be

jQuery(function($) {
    $('tr.concept2').html('<td>new data</td>');
});

I suggest you get very familiar with the API.


try this one.

jQuery(document).ready(function($) {
    var rows = $('.concept2');
});

This will work on page ready event.

Thanks.


$("tr.concept2");

That ensures that only trs named concept2 will be selected, and not other elements. If there is only one <tr class="concept2">, use an ID instead.


You Can Use .each jquery method to do that..

 $("table").find("tr").each(function() { 

                $(this).find('td.start').text('hi'); 

                //if we want to append the text of the td's then we use 

                //$(this).find('td.concept2').append($('<div>HIHI</div>'));
             });

Hope This will helps you? +1 If Helpfull

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜