I have a button that looks like the following:
<button type="submit" class="desktop-button tiny" onclick="document.stacks_in_3151032_page6.formAction.value = 'login';">LOGIN</button>
I am unable to modify the code of the button so I want to know if I can add a name to the button using jQuery or JavaScript? I want the button to look like the following:
<button type="submit" class="desktop-button tiny" name="login_button" onclick="document.stacks_in_3151032_page6.formAction.value = 'login';">LOGIN</button>
attr('name', 'login_button');to do what you need, however this sounds like an XY question. What is the issue you're trying to solve by adding thenameattribute?id="login-button".document.querySelector(???).setAttribute('name', 'login_button')'. But for best answer you need to provide more details. You don't want to select this button by very generic class.tiny. So in order to locate button reliably, you need to base selector on HTML structure.