Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery .load and $this

Tags:

jquery

I have a small problem with JQuery .load that´s driving me nuts - I am quite sure it is simple, but I have been staring at it for too long now :)

I have the following in a .ready(function() {

$('.content_s').load('url/path/aspxpage?dataid='+$(this).attr('data')); 

and 1 or more .content_s classed div with a data="data" section, but I cannot get the data attr - i just get undefined, regardless of the number of divs or what I set as data. The aspxpage gets called alright, just not with the data attr.

As mentioned, I think I have stared myself blind on this, so any suggestions would be most welcome.

Regards

like image 649
user1747519 Avatar asked Jun 10 '26 04:06

user1747519


1 Answers

You need to use .each in such case:

$('.content_s').each(function() {
    var $this = $(this);
    $this.load('url/path/aspxpage?dataid='+$this.attr('data'));
});
like image 196
xdazz Avatar answered Jun 22 '26 20:06

xdazz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!