I’m trying to get to the default home link(href) on my sharepoint site using jquery but i keep getting href is undefined.
I would like to change it to another URL
I have tried
alert($(".static selected menu-item")[0].href).text();
<div class="s4-lp s4-toplinks">
<div class="s4-tn" id="zz17_TopNavigationMenuV4">
<div class="menu horizontal menu-horizontal">
<ul class="root static">
<li class="static selected">
<a accesskey="1" href="/sites/Home" class="static selected menu-item" style="height: 11px; margin-top: 0px;">
<span class="additional-background">
<span class="menu-item-text">Home</span>
<span class="ms-hidden">Currently selected</span></span></a>
</li>
Any ideas what i’m doing wrong
Thanks
Pay close attention to your selector. Class names must start with a dot (
.), whereas tag names do not.Your selector reads:
Which means “a
menu-itemelement that is inside an element of typeselectedthat is inside an element with a class ofstatic.From your markup, it is unclear what the correct selector is. If you want to select an anchor tag with all three classes, use this:
If you want to select an element with the class
menu-iteminside an element with a class ofselected, inside an element with the classstatic, use this: