I have a variable which is a portion of html :
<p>this is a test</p>
<ul>
<li>test1</li>
<li>test2</li>
<li>test3</li>
</ul>
<p>more content</p>
<ol>
<li>number 1</li>
<li>number 2</li>
<li>number 3</li>
</ol>
<p>more content again34234</p>
<ul>
<li>test4</li>
<li>test5</li>
<li>test6</li>
</ul>
<p> </p>
I want to manipulate the variable to find the ul elements and add a class. Then I also want to add a class to the li elements which are within ul only (so do not add a class to the ol li elements).
My code is this but it doesn't seem to do anything:
var itemValue = '<p>this is a test</p>\n' +
'<ul>\n' +
'<li>test1</li>\n' +
'<li>test2</li>\n' +
'<li>test3</li>\n' +
'</ul>\n' +
'<p>more content</p>\n' +
'<ol>\n' +
'<li>number 1</li>\n' +
'<li>number 2</li>\n' +
'<li>number 3</li>\n' +
'</ol>\n' +
'<p>more content again34234</p>\n' +
'<ul>\n' +
'<li>test4</li>\n' +
'<li>test5</li>\n' +
'<li>test6</li>\n' +
'</ul>\n' +
'<p> </p>';
console.log(itemValue);
$(itemValue).find("ul").addClass("CLASS_TEST");
console.log(itemValue);
What am I doing wrong?
Thanks.
itemValuevalue in a single line.divorspanwithid? then you can call$('#somediv').find('ul').addClass('YOUR_CLASS');