6

My HTML:

<button class="btn btn-primary cl-width" ng-click="search()">
  <i class="icon-search icon-white"></i>&nbsp;Search</button>
<button class="btn cl-width" ng-click="criteriaModel.reset()">
  <i class="icon> iconfa-undo"></i>&nbsp;Reset</button>

My jQuery:

$("button[ng-click:'search()]")

It shows an error:

Error: Syntax error, unrecognized expression: button [ng-click:'search()]

Doesn't jQuery support attribute selector for button element? I can achieve that by $("button.btn-primary"), but I don't think that is good enough.

How could I select a button element by its attribute?

1
  • Ya you have a syntax error in your selector... What about just reading the selector you are using? Commented Sep 11, 2013 at 8:54

3 Answers 3

17

Try

$("button[ng-click='search()']")
Sign up to request clarification or add additional context in comments.

Comments

6

Try this

$("button[ng-click='search()']").text()

DEMO

Comments

1

please use the following

$("button[ng-click='search()']")

1 Comment

No, the extra space after button space makes it not working.

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.