var positions = [ "00", "01", "02", "03", "04", "05" ];
jQuery.each( positions, function(players) {
var playerNotesContent = document.createElement('div');
playerNotesContent.setAttribute('id', 'player_stats_block'+this);
$("#player_stats_block" + this).append (columns);
})
I would like to know, why the .append command doesn’t work with the +this, but while creating div it works. What am I doing wrong? Sorry for my bad English and thanks a lot in advance!
UPDATED!
var positions = [ "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18" ];
jQuery.each( positions, function(players, value) {
var player_id = $("#ctl" + value).attr("href").match(RegExp('players/([^/]+)/details.php$'))[1];
var playerlink = document.getElementById("ctl" + value);
GM_xmlhttpRequest({
method: 'GET',
url: 'http://www.test.com/players/item/' + player_id,
onload: function(responseDetails)
{
var page = jQuery(responseDetails.responseText);
var columns = jQuery('div.columns',page);
var playerNotesContent = document.createElement('div');
playerNotesContent.setAttribute('id', 'player_stats_block'+value);
playerlink.parentNode.insertBefore( playerNotesContent, playerlink.nextSibling );
$('#player_stats_block00').append (columns);
}
});
});
Like this all values gets appended in #player_stats_block00! I tried several of your answers but i cant get them appended to their correct #player_stats_blockXX. Sorry again for my bad english and thank you all for your help!
Your code is creating a div and setting its
id, and then trying to look up thatdivby that ID. The lookup will fail, because thedivhasn’t been added to the DOM anywhere yet.If you’re trying to append the div to
columns, you probably want this instead of your last line:(Note that
appendadds content to the container you call it on.)That assumes
columnsis a jQuery object. Otherwise:or
(Note that
appendToadds the content you call it on to the argument you give it; it’s the converse ofappend.)It’s also worth noting that the divs being created have no content, so unless you’re styling them, they won’t have any dimensions and will be kinda hard to find on the page. 🙂
Here’s an example assuming
columnsis a jQuery object, and giving the divs some content so you can see them: Live copy | sourceHTML:
JavaScript: