jQuery: Adding li element only if it not already there?
- by Legend
I am constructing an <li> element like this:
var element = $("<li></li>")
.html(mHTML)
.attr('id', "elemid");
I am trying to add this element to a <ul> element only if it doesn't already exist. Any ideas on how to do this? Am I supposed to use contains() to see if the ul element contain the html and then decide? For instance,
<ul id="elemul">
<li id="elemli1">Element 1</li>
<li id="elemli2">Element 2</li>
<li id="elemli3">Element 3</li>
</ul>
If I try adding Element 1, it should not add it. What should I do if its a longer string (not really long but about 150 characters). Do I go about using hashmaps?