javascript - Capture Link from onClick Event -
our contact page under support directory want test if contact-us in url , 1 thing if not else. "this" not valid - how full value of link under execution, e.g., "www.example.com/support/cars.html" or "www.example.com/support/contact-us.html"
jquery('a[href*="www.example.com/support"]').click(function(event){ event.preventdefault(); if (this.indexof("contact-us") > -1) { alert('contact us'); } else { alert('support'); } });
thanks
use href attr. can using attr()
jquery('a[href*="www.example.com/support"]').click(function(event) { event.preventdefault(); if (jquery(this).attr('href').indexof("contact-us") > -1) { alert('contact us'); } else { alert('support'); } });
Comments
Post a Comment