0

I think that I will learn something about how Javascript thinks, and as a PHP coder that will be a big help. I have provided a link to a working model here, it's a tab interface, very simple:

http://mypilotsupply.com/console/dev.click.php

click on any tab to see what I mean.

If I physically "click" on a tab, it shows that layer and hides the others.

My QUESTION is, how can I write the following, either:

document.getElementById('tab_history').onclick();

or

$('#tab_history').onclick();

since the function I wrote is bound to that class, I can't figure out how to effect the same as if I'd clicked it.

Again, your answer is appreciated and will probably give me some insight into the concept of functions and anonymous functions.

1

2 Answers 2

2

you can use .click() to manually trigger the click handlers - note: the default action of the click event may not get triggered by this because of browser restrictions

$('#tab_history').click();
Sign up to request clarification or add additional context in comments.

1 Comment

that did the job - and it's remarkable to me in that I can get to the element in one way (#tab_History) when the function applied to ('.tabRaise a') - nice when something is smart!
1

For example use click: $('#tab_history').click(); or

You could use trigger(); as alternative.

$('#tab_history').trigger('click');
<ul>
    <li>
        <a href="#inline">Test</a>
    </li>
</ul>

$(document).on("click", "a", function(){
    $(this).text("It works!");
});

$(document).ready(function(){
    $("a").trigger("click");
});

3 Comments

This binds an event handler, it doesn't trigger one.
Yes obviously. It does not trigger but in case he wanted to add some event to the button click.
That's not what the question is about IMO.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.