Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
jQuery how to find all the <li> with "-" values?
Old 04-11-2012, 10:38 PM jQuery how to find all the <li> with "-" values?
TWD
TWD's Avatar
King Spam Talker

Posts: 1,298
Trades: 0
I have an unordered list of all the features of each product.

Some of those features are blank though, as in Not-Applicable.

So I want to add a class of "my-hidden" to those rows which have a value of "-"

So the DOM looks like this.

HTML Code:
<ul id="mylist">
<li><span>Label One</span> - </li>
<li><span>Label Two</span> foobar </li>
<li><span>Label Three</span> - </li>
<li><span>Label Three</span> foobar </li>
</ul>
I want to attach the class of "my-hidden" to the first and third <li>.
I'll then use CSS to do the rest.

How can I do that? I assume i need some kind of "for each" loop that
looks at all the <span> siblings and compares whether they contain the text "-" ?

Anyone?
__________________

Please login or register to view this content. Registration is FREE
"Order a PEBBLE Smart Watch for Bluetooth connection to your iPhone or Android" - 100% Waterproof - 7+ days Battery Charge - High Res Outdoor Readable - Vibrating Alert - Incoming Caller ID

Last edited by TWD; 04-11-2012 at 11:10 PM..
TWD is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-12-2012, 07:29 AM Re: jQuery how to find all the <li> with "-" values?
lizciz's Avatar
Super Spam Talker

Posts: 845
Name: Mattias Nordahl
Location: Sweden
Trades: 0
I'm a bit rusty at this, so you'll probably have to varify at the jQuery website, but something like this should work.

Code:
$("#mylist").children().each(function(){
   var content = $(this).html(); // I think "this" should refer to the <li> elements

   // some regex to find the "-"
   var pattern = / - $/; // This should match any string that ends with " - "
   if (content.match(pattern)) {
      // add the my-hidden class
      this.addClass("my-hidden");
   }
});
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.

Last edited by lizciz; 04-12-2012 at 07:32 AM..
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Reply     « Reply to jQuery how to find all the <li> with "-" values?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.19569 seconds with 11 queries