0

The button I need the script to click is setup like this:

<div id="closer" style="visibility: visible;">
    <input style="height:32px" type="button" onclick="javascript:showIt('hide');" value="Click here to return to AdventureQuest">
</div>

The thing that I can't figure out is how to reference the button as a variable, since the button has no id the getElementByID() won't work. I think that in order to reference the button I need to reference the <div> element somehow.

  • on which event you want button click ? – Pratik Joshi Mar 11 '14 at 13:48
  • Try `$("div#closer input")` – blgt Mar 11 '14 at 13:49
  • Your question is not clear. please give more data and sample. any way you can use $('input[type="button"]','#closer') to access your button – Mahmoud Moravej Mar 11 '14 at 13:52
  • Concerning a DOM change event, have a look at apsillers awnser to this question: http://stackoverflow.com/questions/2844565/is-there-a-jquery-dom-change-listener When a DOM change event is fired, check for the existence of the div#closer via id and if it exists trigger the showIt() function on the unsafeWindow Object with the 'hide' parameter, as this function seems to be bound to the window object. Hope this helps you to get a basic idea. For more detailed help, i'll need more information. – r4vn Mar 11 '14 at 14:20

2 Answers2

0

Your question is confusing.. you need a selector to find the button? $('#closer>input[type=button]') ...

and in the question title you say clicks on a button automatically? trigger a click on it:

$('#closer>input[type=button]').trigger('click'); 
JF it
  • 2,403
  • 3
  • 20
  • 30
0

You can use

getElementByTagName(input);

This will give you back an array of all input tags on the page. If this is the only input tag use

getElementByTagName(input)[0];

If you use jQuery, you can access it easier by fetching the div first and then selecting the input. Use the .trigger() to trigger actions.