Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select button by value

Tags:

jquery

How do I select a button with specific value with jQuery?

<input type="button" value="My task"> 
like image 537
santa Avatar asked Jul 01 '11 20:07

santa


People also ask

Can a button have value attribute?

The value attribute specifies the initial value for a <button> in an HTML form. Note: In a form, the button and its value is only submitted if the button itself was used to submit the form.

How to show value of button in HTML?

The value property sets or returns the value of the value attribute of a button. The value attribute specifies the underlying value that is associated with a button. Important: If you use the <button> element in an HTML <form>, different browsers will submit different values.

Can I get element by value in JavaScript?

Introduction to JavaScript getElementsByName() methodThe getElementsByName() accepts a name which is the value of the name attribute of elements and returns a live NodeList of elements. The return collection of elements is live.


2 Answers

You can use the attr=value selector:

$('input[type="button"][value="My task"]') 

example: http://jsfiddle.net/niklasvh/yAUkC/

like image 193
Niklas Avatar answered Sep 21 '22 14:09

Niklas


Like:

$('input[type=button][value=My task]'); 

You want to select by attributes: jQuery page.

So it says: select inputs of type button with value My task.

like image 32
pimvdb Avatar answered Sep 21 '22 14:09

pimvdb