Amarnath R Shenoy
Amarnath R Shenoy

Reputation: 5201

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 
});

Upvotes: 7

Views: 37069

Answers (6)

Swarna Sekhar Dhar
Swarna Sekhar Dhar

Reputation: 548

we can use :

$('table > tr > td#Status');
$('table > tr > td#Address');

Upvotes: 0

Amarnath R Shenoy
Amarnath R Shenoy

Reputation: 5201

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 :-)

Upvotes: 14

Abhidev
Abhidev

Reputation: 7253

Using jQuery apply: $('#td_ID')

Upvotes: 0

Deepak Sharma
Deepak Sharma

Reputation: 4170

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');
        });     
});

Upvotes: 3

Use Id Selector

$('#tdID')
//^# followed by html id

Upvotes: 0

Rahul Desai
Rahul Desai

Reputation: 15501

Simply do $("#idHere").

More Info: http://api.jquery.com/category/selectors/

Upvotes: 0

Related Questions