Sunday, 15 May 2011

jquery - Change the inner text of a link -



jquery - Change the inner text of a link -

i have tried couple of different things:

i have dynamic menu, populating parent , sub menus

i need alter inner text within link.

$("li:has('a'):contains('name1')").replacewith('name2'); $("li:has('a'):contains('name1')").text('name2');

none of these seem work remove total link. dont want alter link, text within <a href="linl">name change</a>

<li> <a href="http://www.xxxx.com/sweet-wines/"> fortified & sweetness wines

assuming have

<ul class="js-my-menu"> <li><a href="somelink">name1</a></li> </ul>

then can use

$('.js-my-menu').find('a:contains("name1")').text('new text');

jsfiddle link: http://jsfiddle.net/6w8zpz3r/2/

note, js- prefix in class name best practice approach highlighting classes used hook attaching javascript behavior , should rather not used styling purposes. improves maintainability.

jquery

No comments:

Post a Comment