0

I want to add attr DIV on one of the list according to the values in UL LI as below.

<ul id="menu">
<li><a href="about.html">About</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>

I hope I can add to the list About, but failed.

I use the code like this:

<script type='text/javascript'> 
$(function() {
$('#menu li').html("About").attr("id","active")
}); 
</script>

But it did not work. There is a solution?

Norax
  • 111
  • 7
  • I'm having a hard time understanding what exactly you are trying to accomplish. From my understanding you want to add a DIV tag to the list item based on some criteria is that correct? – aemorales1 Feb 22 '16 at 13:59
  • I mean this. I want to add this kind of code in html `
  • About
  • ` **ID active** automatically appear because they have text `About`. Is this possible? – Norax Feb 22 '16 at 14:05
  • Have updated my answer in light of your comment. See also: http://stackoverflow.com/questions/7321896/jquery-find-element-by-text – fridge_light Feb 22 '16 at 14:11