Search code examples
javascriptjqueryparsexml

What does `$xml = $( xmlDoc )` do?


In javascript / jQuery, the example on this page contains the following code which I am struggling to understand;

var xml = "<rss version='2.0'><channel><title>RSS Title</title></channel></rss>",
    xmlDoc = $.parseXML( xml ),
    $xml = $( xmlDoc ),
    $title = $xml.find( "title" );

Specifically the 3rd line;

$xml = $( xmlDoc )

What does that do? Does that form of syntax have a name that I can Google for to find out about it?

Also, in the code above they seem to be using the convention of prefixing variables that contain jQuery objects with a dollar sign. But if that's the case, then shouldn't the variable xmlDoc in the second line be $xmlDoc instead?


Solution

  • It creates a jQuery object based on the xml specified above, enabling you to use jQuery's methods on it to find nodes and manipulate them.