I am trying to get the following code to work in IE8:
jQuery:
$(".scroll, .tobottom, .video-cta").on("click",function(e){
e.preventDefault();
var target = "#" + $(this).getAttribute("data-target") + " h1";
$("html, body").animate({
scrollTop: $(target).position().top
}, {duration: 2000, easing: "easeInOutQuint"});
});
Basically, the HTML that would be associated with something like this would be:
HTML:
<a class="scroll" href="#" data-target="videocontent">Some content</a>
Because IE8 doesn't support getAttribute, I am trying to find a way to get the data-target in all browsers. Any advice?
getAttribute
isn't a jQuery method -attr()
is:That should work.
Alternately, use the
.data()
method:All jQuery methods are designed to work even in old IE, at least in jQuery 1.x.