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

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -