0

I am trying to get some jquery to click on a div. I've got the ID of the div that I need to be clicked and it's inside some php code:

if(isset($_GET['something'])) {

 echo "<script> $('#huge_it_dots_3_20').click(); </script>";

}

The div I'm targetting looks like this:

<div id="huge_it_dots_3_20" class="huge_it_slideshow_dots_20 huge_it_slideshow_dots_deactive_20" image_key="3" image_id="33" onclick="huge_it_change_image_20(parseInt(jQuery('#huge_it_current_image_key_20').val()), '3', data_20,false,true);return false;"></div>

My issue is that for some reason it's not clicking on the div.

And ideas why?

3
  • where did you put your php code? above?or below the div? Commented May 20, 2015 at 10:34
  • 1
    Try with this: echo "<script> $('#huge_it_dots_3_20').trigger("click"); </script>"; Commented May 20, 2015 at 10:35
  • declare the method in the domReady event Commented May 20, 2015 at 10:57

4 Answers 4

2

Try with this:

echo "<script> $('#huge_it_dots_3_20').trigger('click'); </script>";
Sign up to request clarification or add additional context in comments.

1 Comment

if you paste this code before the HTML element itself, it won't trigger anything. proof here , but, if you check up my answer with the readyState you'll see it works. fiddle here
2

warp the code with dom ready function.. then it should work

  if(isset($_GET['something'])) {

     echo "<script> $(document).ready(function(){$('#huge_it_dots_3_20').click();}) </script>";

    }

Comments

1

Do something like

<?php if(isset($_GET['something'])) { ?>

 <script> 
  $('#huge_it_dots_3_20').click();
 </script>
<?php } ?>

Comments

1

The JS code will run before your DOM will be ready so.. here's a readyState.

<?php if(isset($_GET['something'])) { ?>

    <script type="text/javascript">
         $(function(){ 
             $("#huge_it_dots_3_20").click()
         });
    </script>

<?php } ?>

Comments

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.