My jQuery question I beleive is pretty simple, which is driving me insane that I can’t get it.
I have an object with a property “content”, I want to be able to take that object, manipulate the property “content” with jQuery and then overwrite the value with the new value jQuery creates.
Example:
o.content = "<div><span>hello</span></div>";
$('div', o.content).addClass('test');
At this point I want o.content to be equal to <div class='test'><span>hello</span></div>
I can not for the life of me figure out the syntax. Any help is really appreciated.
from the docs of the jquery function,
contextmust beYour context (
o.content) is a string. Also, the jQuery function is not able to select the entire context, it can only select elements in that context.Try this instead:
http://jsfiddle.net/JfW4Q/