Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select a td from a table with id using jQuery

I have a table with td's with id. I need to select those td's and reorder the columns.

$('table tr').each(function () {
    var tr = $(this);
    var tds = $('#Status');
    var tdA = $('#Address');
    alert(tds.innerHtml); //Here am getting a blank msg
    tds.remove().insertAfter(tda); //This is what i need to do 
});
like image 667
Amarnath R Shenoy Avatar asked Feb 12 '14 06:02

Amarnath R Shenoy


2 Answers

I found the answer:

var tds = tr.find("td[id='Status']"); //what i was looking for

Thanks for ur support and special thanks for voting my genuine question 2 points down :D, since iam not point hungry, No offense :-)

like image 98
Amarnath R Shenoy Avatar answered Oct 13 '22 00:10

Amarnath R Shenoy


var selectedTd = $("#ID_OF_TD");

or to call the method like on click etc etc you can directly call the method

$("#ID_OF_TD").click(function(){

});

you need to put this code in document ready section ..

$("document").ready(function(){             
        $("#ID_OF_TD").click(function(){
            alert('td clicked');
        });     
});
like image 34
Deepak Sharma Avatar answered Oct 13 '22 01:10

Deepak Sharma