views:

45

answers:

2

The append cmd doesn't close my tags, but why? What do i have to change?

for (var i = 0; i<=4; i++)
     $("#wrapper").append('<li id=img'+i+'></li>');

always creates only <li id=img1> and so on but no </li>?!

Thanks for your help!

+3  A: 

Your code should be:

for (var i = 0; i<=4; i++)
    $("#wrapper").append('<li id="img'+i+'"></li>');

I think you forgot the quotes for the id attribute

Guillem Gelabert
without the doublequotes it generated them by itself.
+1  A: 

The code you provided does seem to add the tags you want.

If I run the exact javascript you provided, viewing generated source using the web developer toolbar in firefox gives me <li id="img2"></li> and inspecting the element in firebug shows me <li id="img2"/>.

Both of those are closed and proper xhtml. Though if you aren't using xhtml, the closing tag isn't required anyway.

chrismjones