Link to home
Create AccountLog in
Avatar of areyouready344
areyouready344Flag for United States of America

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()
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of areyouready344

ASKER

thanks leakim, it works but one quick question, how do I get the prev() in this list, I tried the following but not working.


alert("check li variable value: " + $("#set li").prev().html());
$("<ul id='set'><li>" + variable + "</li></ul>");
there's only one li
so there's no li before
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());
no, that's why I replace your previous code with html()
val() is for value
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.


SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Each time through the each loop, the html() says null,

alert("check li variable value: " + $("#set li").prev().html());
Of course that makes sense, thanks leakim...
its working, thanks for really understanding this issue...