1

I've tried different solution without much success.

I'm able to add a <li> to my list, but the DOM does not recognize it as a list element and thus I'm not able to manipulate it with jQuery later.

This is the last code I've tried, but I get the error msg:

TypeError: $('</li>').class is not a function

Code:

 var data = '<div> some stuff</div>';
 var index = "index-" + brand_name[0].toLowerCase();

 $("</li>")
   .class(index)
   .text(data)
   .insertAfter($(".brand_list .main-"+index))
   .css('display','list-element');

I've also tried with <li></li> and <li> but I get the same error.

Any help much appreciated.

7
  • 1
    Use .addClass instead of .class... Commented Aug 2, 2012 at 22:01
  • @RobW Thanks, that helped. My next trick is to add css style. .css() is not doing it. Any suggestions? Commented Aug 2, 2012 at 22:03
  • Why not have that style in the class you add? Commented Aug 2, 2012 at 22:04
  • Why are you closing the element like that? --> $('<li/>') Commented Aug 2, 2012 at 22:07
  • 1
    @Steven list-element is not a valid display property. Use list-item. Commented Aug 2, 2012 at 22:07

1 Answer 1

5

you should be using .addClass() instead of .class(). More info here: http://api.jquery.com/addClass/

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, that helped. Do you know how I can add CSS class? .css() is not working.
the .addClass() method adds a css class to your element... please read the documentation link I posted.
Sorry misread your question. .css() is correct, but your display:list-element is not. try list-item instead of list-element
Thanks, that was it. One last question. I'm populating the <li> with a few html elements. Like the code is not, the html elements are shown in clear text. So I guess I hve to create these elements much inthe same way. How do I Add these to the li? By creating the element, then us li.append() ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.