Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You're running <code>cloneNode</code> on a jQuery object. You start off with native API, then convert it to a jQuery object, then switch back.</p> <p>I suppose you could do:</p> <pre><code>genres_html.appendChild( genre.get(0).cloneNode(true) ); </code></pre> <p>But then I suspect you would lose your <code>data</code>.</p> <hr> <p><strong>EDIT:</strong></p> <p>If you want jQuery, instead of creating a fragment, try creating an empty jQuery object, then pushing each genre into it:</p> <pre><code>var genres_html = $(); ... genres_html.push( genre ); </code></pre> <hr> <p><strong>EDIT:</strong></p> <p>Give this a try. I'm no DOM expert, but it may work for you.</p> <pre><code>var genres_html = document.createDocumentFragment(); $(xmlData).find('genres').each(function(i, node) { var genre = document.createElement('a'); genre.setAttribute('class','button'); genre.setAttribute('href', 'javascript:void(0)'); var $node = $(node); genre.setAttribute('genreData', $node.find('genreID:first').text() ); genre.innerHTML = $node.find('genreName:first').text(); genres_html.appendChild( genre.cloneNode(true) ); // Not sure why you would need to make a clone?? }); var list = document.getElementById('list'); list.appendChild(genres_html); // error: $('#list a:first').data('genreData') is null alert($('#list a:first').attr('genreData')); </code></pre> <p>Let me know if it works.</p> <p>EDIT: Changed my error with innerHTML</p> <p>EDIT2: Using native innerHTML to append to <code>#list</code></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload