Marie J Marie J - 6 months ago 47
jQuery Question

How can I get just the first word from an address link text with jQuery?

I have the following:

<a title="Home" href="#">Home test test</a>

I can use a.html() to get me "Home test test" but what I need is just the first word "Home". Is there an easy way that I can do this with jQuery?

Answer Source


split: (further read if you keen)

another demo using match (using match)



  alert($('a').html().split(' ')[0]);    


code using match api

  var str = $("a").text().match(/\w+/);


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download