javascript - trying to extract a string from a js this keyword -
i'm trying execute javascript after link clicked before loading link, using code:
$('body').on("click", 'a', function (evt) { evt.preventdefault(); console.log(this); $('.content').addclass('hide'); if (this.search("av") > 0) { $('#avheader').addclass('fullwidth'); } settimeout(function () { window.open(this, "_self"); }, 500); });
my errors are:
this.search
isn't function ,
window.open(this, "_self");
doesn't work
wanted put question out there since couldn't find simple explanation , i'd spend half day trying figure out..
when in event handler this
points clicked link. there no search
method element. trying search string somewhere in link, maybe content.
$('body').on("click", 'a', function (evt) { evt.preventdefault(); console.log(this); $('.content').addclass('hide'); if (this.innerhtml.search("av") > 0) { $('#avheader').addclass('fullwidth'); } settimeout(function () { window.open(this.href, "_self"); }.bind(this), 500); });
Comments
Post a Comment