For some reason, this works:
var oldText = $("#tayke li:eq(" + theIndex + ")" ).text();
But this doesn't:
var tayke_li = "#tayke li:eq(" + theIndex + ")"
var oldTest = $( tayke_li ).text();
Note: theIndex is an integer.
For some reason, this works:
var oldText = $("#tayke li:eq(" + theIndex + ")" ).text();
But this doesn't:
var tayke_li = "#tayke li:eq(" + theIndex + ")"
var oldTest = $( tayke_li ).text();
Note: theIndex is an integer.
Does it make any difference if you put the semi-colon at the end of then line:
var tayke_li = "#tayke li:eq(" + theIndex + ")"; //<---
I've set up a simple example, and it works fine:
alert($("#tab1").length);
var s = "#tab" + String(1); //alerts "1"
alert(s); //alerts "#tab1"
alert($(s).length); //alerts 1
Also, try an explicit cast of theIndex
to a string using String()
. Have you double-checked what is stored in tayke_li
Semicolons Required?
http://stackoverflow.com/questions/1031718/what-is-the-consequence-of-this-bit-of-javascript
http://stackoverflow.com/questions/537632/should-i-use-semi-colons-in-javascript-closed
It works both ways. I've redone it and it worked. Check the theIndex variable for changes and scope. Try replacing it with hardcoded 1
adding jQuery version info to the question, and a browser spec would be nice too.
try
var oldText = $("#tayke li:eq("+parseInt(theIndex)+")").text();
or
var oldText = $("#tayke li").eq(theIndex).text();