css - JQuery: adding class to element if it has text -


I have a series of links in ul, some have text and nothing else, eg:

  & lt; Ul & gt; & Lt; Li & gt; & Lt; A href = "google.com" & gt; Google & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "yahoo.com" & gt; Yahoo & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "bing.com" & gt; Bing & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; & Lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; & Lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; & Lt; / A & gt; & Lt; / Li & gt; & Lt; / Ul & gt;   

I just want to use JQuery to apply a tag to that category in which it has text.

So far I have this:

  var buttontext = $ ('ul a'). Text (); If (buttontext.length & gt; 0) {$ ('ul A'). AddClass ('Buttonfet'); }   

But the class is still affecting all the tags. I was just wondering if anyone could tell me in the right direction?

Thanks

  $ ("ul a"). Each (function (i, e) {var $ e = $ (e); if ($ e.text (). Length> 0) {$ E.addClass ("buttonfetch");}});    

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -