2

I am trying to simulate a click on a div when the page loads and detects a 'settings' in the url using php. How come this does not work?

if(isset($_GET['settings'])){ ?>
       <script>
           $(function(){
              $('#3').trigger("click"); //tried .click();
           });
        </script>
<?php }
Gadgetster
  • 473
  • 3
  • 12
  • 33

1 Answers1

1

Numeric IDs are invalid in Jquery.

For more info Goto this post

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

So try to use $('.slide').trigger("click"); instead of $('#3').trigger("click"); or put some valid id and select using that.

Using this code will solve your problem

<html>
<head>
    <title>Click </title>
</head>
<body>
    <div class="slide">Show Target</div>
    <div style="display: none;" class="target">Target</div>
    <div class="hide-target">Hide Target</div>
<?php
    $_GET['settings'] = "some value";
    if(isset($_GET['settings'])){
?>      <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
        <script>
            $(document).ready(function(){
                $('.slide').click(function(){
                    alert("hi");
                    $(".target").show();
                });
                $('.hide-target').click(function(){
                    $(".target").hide();
                });
                $('.slide').trigger("click");
            });
        </script>
<?php
    }
?>    
</body>

Community
  • 1
  • 1
Mad Angle
  • 2,347
  • 1
  • 15
  • 33