areyouready344
asked on
how to create a ul and li and then test the variable?
how to create a ul and li and then test the variable? Not working...
var variable = 0;
$("<ul id='set'><li> + variable + </li></ul>");
alert("check li variable value: " + $("#set li").val()); or alert("check li variable value: " + $("#set li").text());
Not working, returning undefined when using val()
and empty when using .text()
var variable = 0;
$("<ul id='set'><li> + variable + </li></ul>");
alert("check li variable value: " + $("#set li").val()); or alert("check li variable value: " + $("#set li").text());
Not working, returning undefined when using val()
and empty when using .text()
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
$("<ul id='set'><li>" + variable + "</li></ul>");
there's only one li
so there's no li before
there's only one li
so there's no li before
ASKER
Thanks for letting me know this but I have the ul list in an each loop. Is this syntax correct,
alert("check li variable value: " + $("#set li").val());
alert("check li variable value: " + $("#set li").val());
no, that's why I replace your previous code with html()
val() is for value
val() is for value
ASKER
This is not working.
alert("check li variable value: " + $("#set li").prev().html());
But each time through the each loop, this value increments..
alert("check the total loop count of set list: " + $("#set li").length);
This means to me #set list contains values.
alert("check li variable value: " + $("#set li").prev().html());
But each time through the each loop, this value increments..
alert("check the total loop count of set list: " + $("#set li").length);
This means to me #set list contains values.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Each time through the each loop, the html() says null,
alert("check li variable value: " + $("#set li").prev().html());
alert("check li variable value: " + $("#set li").prev().html());
ASKER
Of course that makes sense, thanks leakim...
ASKER
its working, thanks for really understanding this issue...
ASKER
alert("check li variable value: " + $("#set li").prev().html());