Ok, correct me if I'm wrong, but I take it that jQuery attr()
does NOT work in IE. (marked wontfix) That being the case, what is the best alternative? For example, this works everywhere but IE:
jQuery(document).ready(function($) {
$('.airsrc').each(function() {
var $this = $(this);
var src = $this.attr('data-websrc');
$this.attr('src', src);
});
});
Update: Whoops...I realize the issue. I actually had this inside an if
statement based on a CSS3 media query. Media queries that aren't natively supported in IE8 or lower. The attr()
definitely works!
I use attr
with data-*
attributes on IE all the time, I've never had a problem. Here's a live version, just tested in IE6, IE7, and IE9. Don't have my IE8 box handy, but again, I've never had a problem.
I haven't had a problem with attr()
working in IE. The description of the bug listed is:
JQuery function .attr does not works under IE, when attribute is event like .attr("onchange","alert('Hello event onchange!')"); . It is because IE does not understand this. You can check, if attribute is event, make eval function if IE.
Specifically, it has to do with events. Regular attributes shouldn't be a problem.
please try this:
$this.data('websrc');
instead of $this.attr('data-websrc');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With