javascript - Change link color onclick without preventDefault() -
i need alter color of link if clicked.
if utilize event.preventdefault();
color applied permanently link doesn't work, uri isn't passed , can't utilize $_get['route']
since using mod_rewrite redirect uri's $_get
var. ^(.*)$ index.php?route=$1
if don't utilize event.preventdefault link works , section changes, addclass applied while i'am clicking, dissapears...
how can both behaviours ? able pass uri (href), , permanently alter color onclick
?
html:
<a href="./section">section</a>
css:
.active { color: #f00; }
jquery:
$('a').on('click', function(event) { //event.preventdefault $(this).addclass("active"); });
you can seek in doc ready
there no need specify .click()
event:
$(function(){ var url = window.location.href; // url should way 'http://aaa.com/page/section' var link = url.substr(url.lastindexof('/') + 1); // here 'section' $('[href*="' + link + '"]').addclass("active"); // if found add together class });
javascript jquery html css events
No comments:
Post a Comment