this
in that code is the window (the global object). I think you probably meant for it to refer to the element that has the data-*
attributes on it.
You probably want to handle those elements individually, so your best bet is to find them and loop through them with each
, which will let you target them individually and will call your callback with this
referring to each one:
$('.html[data-load-file][data-load-content]').each(function() {
var $this = $(this);
$this.load($this.attr("data-load-file") + ' ' + $this.attr("data-load-content"));
});
or:
$('.html[data-load-file][data-load-content]').each(function() {
$(this).load(this.getAttribute("data-load-file") + ' ' + this.getAttribute("data-load-content"));
});
That finds all elements with the class html
and also the two data-*
attributes we require, loops through them individually, and uses their attributes to call load
.
Live on plunkr: http://plnkr.co/edit/lzHBYxVSETvHzTt6l2KR?p=preview
Side note: I switched the above to using attr
rather than data
, because there wasn't any indication you're using the features data
provides. Remember that data
is not an accessor for data-*
attributes. It's both more and less than that. Details.