jquery - Turn anchor value to parent li class -
I'm new to jQuery, I'm trying to get it anchor value to start the parent le class .
The code I'm trying to do:
jQuery ('ul.menu'). Every (function () {var turnclass = jQuery (this). Find ("a"). Val (); Jquery ('ul.menu li') AddClass (turnclass);});
What I want to do here:
& lt; Ul class = "menu" & gt; & Lt; Li class = "home" & gt; & Lt; A href = "#" & gt; Home & lt; / A & gt; & Lt; / Li & gt; & Lt; Li class = "about us" & gt; & Lt; A href = "#" & gt; About us & lt; / A & gt; & Lt; / Li & gt; & Lt; Li class = "contact us" & gt; & Lt; A href = "#" & gt; Contact us & lt; / A & gt; & Lt; / Li & gt; & Lt; / Ul & gt;
.value ()
to get the value of Is an input element, it can not be used with an anchor if you want text inside an anchor, then use .text ()
. Then you need to process your .each ()
loop on each li
, complete ul.menu
.
Comments
Post a Comment