0

How can I make this happen, on page load?

<a onclick="$('a[href=\'#tab-review\']').trigger('click');"><?php echo $text_write; ?></a>

Thanks.

2 Answers 2

2
$(window).load(function ()
{
    $('a[href="#tab-review"]').click();
});

RTFM.


Hm, any idea how to put this between I need this to be executed with IF...?

<script>
function clickTheLink()
{
    $('a[href="#tab-review"]').click();
}

<?php
if ($something) {
  echo '$(window).load(clickTheLink);';
}
?>
</script>
Sign up to request clarification or add additional context in comments.

7 Comments

Why do you recommend $window.load instead of what I consider to be the more "standard" $document.ready?
Because the OP used the words "on page load," not "on document ready."
Tnx for the answers, but can you please tell me how to implement that code? Just to replace mine, with that one, put it between <?php ?> or...? Sorry, can't figure it out :(
@Nikola place the JavaScript code in <script> tags, or in an external JS file referenced by a <script> tag. See also developer.mozilla.org/En/HTML/Element/Script
Thank you guys for you awesome and quick help ;)
|
1

Assuming jquery.

<script>
$(function () {
    $('a[href="#tab-review"]').trigger('click');
});
</script>

6 Comments

This doesn't explain how to hook into page load. Be it $document.ready, $window.load or window.onload.
That is a shortcut for document.ready. api.jquery.com/ready see $(handler);
I really can't figure it out how to put this code, same as the above one... Can you please write me the full code for this to work? Sorry again :(
Added script tags, just place them in your html.
Thank you guys for you awesome and quick help ;)
|

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.