Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery change button attributes

I have a button like this:

<input type="button" name="btn" id="btn" value="Proceed"/>

After all processes and get the expected result, I need to apply some changes on this button.

  1. Change the value of this button.
  2. Add something to direct the current page to another one.

I know I can do the first goal using the code below:

$('#btn').attr('value','newValue');

But for the second one, I need something like our previous codes in JavaScript as below:

onclick="window.location.href='newPage.htm'";

Help me please.

like image 874
Mohammad Saberi Avatar asked Apr 09 '26 09:04

Mohammad Saberi


1 Answers

something like, if I understand you correctly:

$("#btn").val("newValue").click(function(){
     document.location = "newPage.htm";
});

This will set a new value and bind a click handler.

like image 142
Niels Avatar answered Apr 10 '26 22:04

Niels



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!