-1

I already tried to googled it but nothing helped me.
I want to trigger the following button:

<input class="btn btn_large btn_green" value="Go" type="submit">

If the element would be an id this would work like a charm:

document.getElementById('btn btn_large btn_green').submit();

But since I can't assign an id to this button this isn't working.
Even if I try to call it via

document.getElementsByClassName("").submit();

it isn't working.

Thanks in advance

Jan
  • 130
  • 8
  • 1
    Well, the element doesn't have the classname that you searched for. `getElementsByClassName("")` for `class="btn btn_large btn_green"`. I also highly doubt that `document.getElementById('btn btn_large btn_green')` works since that element doesn't have an id and the string you indicated is a class and not a valid HTML id. – takendarkk Apr 14 '17 at 16:12
  • why not use `submit()` on the form instead of the button? – Eugen Rieck Apr 14 '17 at 16:13
  • I agree with using submit on the form. If you have to do it through the button you can get the button tag by tagname and use the getAttribute() method to find the type. If the type is submit, you can try to submit the form like that. – user2205967 Apr 14 '17 at 16:16

1 Answers1

2

You can try document.querySelector():

You can then select by class using "." and then click the element to submit.

var button = document.querySelector('.btn.btn_large.btn_green');
console.log(button);
button.click();
<input class="btn btn_large btn_green" value="Go" type="submit">
nitobuendia
  • 1,228
  • 7
  • 18