javascript - jQuery: Adding a class to <a> element -
i have wordpress site , add class links in main navigation using jquery.
this how code looks:
html
<div class="nav-menu"> <ul> <li class="current_page_item"> <a title="home" href="www.example.com">home</a> </li> ... </ul> </div>
and i'd achieve:
html
<div class="nav-menu"> <ul> <li class="current_page_item"> <a title="home" href="www.example.com" class="new-class-goes-here">home</a> </li> ... </ul> </div>
does have clue how this?
you can use jquery's .addclass() method , appropriate selector <a>
tags:
$(".nav-menu a").addclass("new-class-goes-here");
here jsfiddle demonstrate.
Comments
Post a Comment