0

I'm having a hard time selecting all the buttons with value "bar" using jquery.

<div id="1">

   <button>foo</button>
   <button>bar</button>

   <button>foo</button>
   <button>bar</button>

</div>

please note I must start the select from div with id="1"

so something like ... $(#"1 button ....")

Thanks!

3
  • i am not sure that 1 is proper id name Commented Feb 6, 2014 at 23:53
  • 1
    @nevermind It's a valid HTML5 id. Commented Feb 6, 2014 at 23:56
  • 1
    @BlackSheep, Yeees! Finally... :) Commented Feb 6, 2014 at 23:58

2 Answers 2

5
$('#1').children('button').filter(function () {
    return $(this).text() === 'bar';
});
Sign up to request clarification or add additional context in comments.

2 Comments

Sorry I tried this and i'm hiding the bars, but won't work. see: jsfiddle.net/jtQcF
You need to load jQuery: jsfiddle.net/jtQcF/1... check your console for errors, it's your friend!
2

You could use the :contains() selector

$("#1 button:contains('bar')");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.