Talha Habib Talha Habib - 6 months ago 15
jQuery Question

Change Button value on click without id or class

Let's suppose my button is as follows:

<input type="button" value="BLUE" name="button_blue" />


What I want is when I click the button,
value="BLUE"
should be changed to
value="RED"
or anything I want.

Answer

Since the button has name="button_blue" attribute, use Attribute Equals Selector

$('[name=button_blue]').on('click',function(){
  $(this).val('RED');
});

Working demo: http://jsfiddle.net/dw8kmh3g/

Comments