Jquery: Pass Variable To :eq() Does Not Work
I have been trying to find out why the following lines of code do not work: $('#add-cloud > select').change(function() { var selected = parseInt($('#add-cloud select option:
Solution 1:
You have to concatenate your variable with your selector:
$("tr:eq("+selected+")");
Solution 2:
The way you're doing it, you're embedding the actual string "selected"
in the selector. You need to construct a string using your selected
variable as a part of it:
$("#cloud-calculator table tr:eq(" + selected + ")").css("color", "red");
Solution 3:
Also, you can simply use the 'this' object to get the seleted value.
$('#add-cloud > select').change(function()
{
var rowSelector = '#cloud-calculator table tr:eq(' + parseInt(this.val()) + ')';
$(rowSelector).css("color", "red");
}
Solution 4:
Yes we can pass variable to eq() function
. But you need to disable Firebug. Otherwise it wont work.
Please check this example.
var index = 3
$('#sidebar_menu li:eq('+index+')').css({"color":"#050959"});
Post a Comment for "Jquery: Pass Variable To :eq() Does Not Work"