0

I have this button

<button id="stopButton" onClick="stop(); clearInterval(add); ">Sabitle</button>

And I have this function

function displayMessage(message)
        {
            chatTextArea.value = message + "\n";
            chatTextArea.scrollTop = chatTextArea.scrollHeight;

            if(message == "Stop")
            {
                 !!!!! I want to click stopButton in this area !!!!
            }

        }

How can I click this button in function?

3
  • you will have a much easier time if you use jQuery: api.jquery.com/click Commented Aug 21, 2014 at 6:52
  • $("#stopButton").click() Commented Aug 21, 2014 at 6:55
  • I would suggest keeping the html view and js control as separate as possible. AKA having the stopButton call a single function that has the logic for what you need it to do, and use the same funtion in displayMessage(). Commented Aug 21, 2014 at 6:57

3 Answers 3

0

I think you are going about this in a round-about fashion.

Instead of trying to programmatically click the button, why don't you just call the functions that the button calls when clicked?

Sign up to request clarification or add additional context in comments.

Comments

0

Try like this

$("#stopButton").click();

Comments

0

Use:

$("#stopButton")[0].click();

or

document.getElementById("stopButton").click();

2 Comments

From what I've seen, it is document.getElementById("stopButton").click();, not onclick(). And this is the only thing that actually works. JQuery (at least my version) simply doesn't work for this.
Yup. should be click and not onclick. will update that. thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.