1

I have got the following code in html

      <div class="functionitem" id="viewresult"><span class="button"><span>
      <input type="button" class="form_button" value="  View"></span></span>
       </div>

So I try to using the following jquery click function to invoke a method when the button get clicked, this is what I have done

      $("#viewresult:button").click(function () { 
      //methods
          });

But it's not working, what did I do wrong, please help, thanks

6
  • 1
    What does the colon do? Try #viewresult input[type=button] Commented Sep 11, 2011 at 1:25
  • @tjameson It's a special jQuery selector: api.jquery.com/button-selector Commented Sep 11, 2011 at 1:30
  • since you have only one input element in the container with id 'viewresult' you don't need to use button you can just use input like $('#viewresult input').click(funtion()); Commented Sep 11, 2011 at 1:33
  • @Digital Plane - Hrm... I'd recommend using straight CSS3 selectors where possible. Commented Sep 11, 2011 at 1:33
  • 2
    @Ehtesham - Being explicit is good for future-proofing. Commented Sep 11, 2011 at 1:34

3 Answers 3

5

Your selector is wrong. It is trying to find a button with id viewresult. Putting a space between the two will indicate that the button should be a descendant of the viewresult element.

 $("#viewresult :button").click(function () { 
  //methods
 });
Sign up to request clarification or add additional context in comments.

Comments

0

Leave a space in your selector. :button is a descendant of #viewitem, not a qualifying property. e.g.

$('#viewitem :button').click(...);

That says "a :button that falls under the #viewitem element"

Comments

0
 $("#viewresult input:button").click(function () { 
     //methods
 });

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.