I have html in a var that I am trying to edit. I want to move the UL with class “files” to its own var then remove it from the data var.
I have this so far but doing it wrong. I cant seem to understand it.
var data = '<ul class="dirs"><li class="d"><a href="#" rel="/Games/">Games</a></li><liclass="d"><a href="#" rel="/Log/">Log</a></li></ul><ul class="files"><li class="f"><a href="#">fubar.txt</a></li><li class="f"><a href="#">fubar2.txt</a></li></ul>';
var files = $(data).find("UL.files").html();
Expected Result:
data = '<ul class="dirs"><li class="d"><a href="#" rel="/Games/">Games</a></li><li class="d"><a href="#" rel="/Log/">Log</a></li></ul>';
files = '<ul class="files"><li class="f"><a href="#">fubar.txt</a></li><li class="f"><a href="#">fubar2.txt</a></li></ul>';
Thanks
You can’t modify the string, but you can create new strings.
This places a new UL element into
ul1andul2. Then to get thehtmlstring, you use the.outerHTMLproperty.Because
Firefoxdoesn’t supportouterHTML, you need a hack to make it browser compliant.Example output: http://jsfiddle.net/bjgLV/