Accessing Siblings In Jquery
I want to access the sibling of a column : 1 2 3 When i click over 3, how c
Solution 1:
You can use -
$('td:last').on('click', function(){
$(this).siblings('td:first').css('color', 'red');
})
Solution 2:
Solution 3:
If I well understood;
var td = $('tr td'), len = td.length;
td.on('click', function() {
var i = (td.index(this) + 1) % len;
console.log(td.eq(i));
});
this will return
- 2nd
td
when you click on 1sttd
- 3rd
td
when you click on 2ndtd
- 1st
td
when you click on 3rdtd
example fiddle: http://jsfiddle.net/BmYue/2/
Solution 4:
or you could use .parent() and .children() method as well to access it.
$(this).parent().children()
But easier version is .siblings jquery function.
http://api.jquery.com/parent/ http://api.jquery.com/children/
Post a Comment for "Accessing Siblings In Jquery"