After click link how to trigger onclick on another page by id?












0















I've got a question.
Let's say I've got two pages.
On first page I've got link:



<a href="www.secondpage.com#changefirst">


And on the second page, I've got



<p onclick="changeVisibility('#point_4')" id="changefirst></p>
<div id="point_4"></div>


And I've got a lot of paragraphs on my second page.
How can I trigger on the second page that if there's a link with specific "#" then when the second page load specific paragraph is onclick triggered?



I was trying to make something with:



$('#changefirst').trigger('click');


or with:



if (hash) {
$('#changefirst').trigger('click');
}


but it's not working, I dunno if I'm going a right way.
Thanks for the help!










share|improve this question

























  • is $('#changefirst').trigger('click'); already inside document.ready?

    – ACD
    Nov 14 '18 at 10:25











  • Hi try $('#changefirst').click();

    – Vara
    Nov 14 '18 at 10:28











  • @ACD when I use document ready its trigger click no matter I get to site via www.secondpage.com#changefirst or www.secondpage.com

    – David
    Nov 14 '18 at 10:31











  • @David check my answer

    – ACD
    Nov 14 '18 at 10:34











  • I have some question. 1. is that p tag take time to load on page? 2. you wan to auto click the element when it's available on page?

    – Shirish Patel
    Nov 14 '18 at 10:44
















0















I've got a question.
Let's say I've got two pages.
On first page I've got link:



<a href="www.secondpage.com#changefirst">


And on the second page, I've got



<p onclick="changeVisibility('#point_4')" id="changefirst></p>
<div id="point_4"></div>


And I've got a lot of paragraphs on my second page.
How can I trigger on the second page that if there's a link with specific "#" then when the second page load specific paragraph is onclick triggered?



I was trying to make something with:



$('#changefirst').trigger('click');


or with:



if (hash) {
$('#changefirst').trigger('click');
}


but it's not working, I dunno if I'm going a right way.
Thanks for the help!










share|improve this question

























  • is $('#changefirst').trigger('click'); already inside document.ready?

    – ACD
    Nov 14 '18 at 10:25











  • Hi try $('#changefirst').click();

    – Vara
    Nov 14 '18 at 10:28











  • @ACD when I use document ready its trigger click no matter I get to site via www.secondpage.com#changefirst or www.secondpage.com

    – David
    Nov 14 '18 at 10:31











  • @David check my answer

    – ACD
    Nov 14 '18 at 10:34











  • I have some question. 1. is that p tag take time to load on page? 2. you wan to auto click the element when it's available on page?

    – Shirish Patel
    Nov 14 '18 at 10:44














0












0








0








I've got a question.
Let's say I've got two pages.
On first page I've got link:



<a href="www.secondpage.com#changefirst">


And on the second page, I've got



<p onclick="changeVisibility('#point_4')" id="changefirst></p>
<div id="point_4"></div>


And I've got a lot of paragraphs on my second page.
How can I trigger on the second page that if there's a link with specific "#" then when the second page load specific paragraph is onclick triggered?



I was trying to make something with:



$('#changefirst').trigger('click');


or with:



if (hash) {
$('#changefirst').trigger('click');
}


but it's not working, I dunno if I'm going a right way.
Thanks for the help!










share|improve this question
















I've got a question.
Let's say I've got two pages.
On first page I've got link:



<a href="www.secondpage.com#changefirst">


And on the second page, I've got



<p onclick="changeVisibility('#point_4')" id="changefirst></p>
<div id="point_4"></div>


And I've got a lot of paragraphs on my second page.
How can I trigger on the second page that if there's a link with specific "#" then when the second page load specific paragraph is onclick triggered?



I was trying to make something with:



$('#changefirst').trigger('click');


or with:



if (hash) {
$('#changefirst').trigger('click');
}


but it's not working, I dunno if I'm going a right way.
Thanks for the help!







javascript jquery html






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 10:43









jnuK

1,5401425




1,5401425










asked Nov 14 '18 at 10:23









DavidDavid

26119




26119













  • is $('#changefirst').trigger('click'); already inside document.ready?

    – ACD
    Nov 14 '18 at 10:25











  • Hi try $('#changefirst').click();

    – Vara
    Nov 14 '18 at 10:28











  • @ACD when I use document ready its trigger click no matter I get to site via www.secondpage.com#changefirst or www.secondpage.com

    – David
    Nov 14 '18 at 10:31











  • @David check my answer

    – ACD
    Nov 14 '18 at 10:34











  • I have some question. 1. is that p tag take time to load on page? 2. you wan to auto click the element when it's available on page?

    – Shirish Patel
    Nov 14 '18 at 10:44



















  • is $('#changefirst').trigger('click'); already inside document.ready?

    – ACD
    Nov 14 '18 at 10:25











  • Hi try $('#changefirst').click();

    – Vara
    Nov 14 '18 at 10:28











  • @ACD when I use document ready its trigger click no matter I get to site via www.secondpage.com#changefirst or www.secondpage.com

    – David
    Nov 14 '18 at 10:31











  • @David check my answer

    – ACD
    Nov 14 '18 at 10:34











  • I have some question. 1. is that p tag take time to load on page? 2. you wan to auto click the element when it's available on page?

    – Shirish Patel
    Nov 14 '18 at 10:44

















is $('#changefirst').trigger('click'); already inside document.ready?

– ACD
Nov 14 '18 at 10:25





is $('#changefirst').trigger('click'); already inside document.ready?

– ACD
Nov 14 '18 at 10:25













Hi try $('#changefirst').click();

– Vara
Nov 14 '18 at 10:28





Hi try $('#changefirst').click();

– Vara
Nov 14 '18 at 10:28













@ACD when I use document ready its trigger click no matter I get to site via www.secondpage.com#changefirst or www.secondpage.com

– David
Nov 14 '18 at 10:31





@ACD when I use document ready its trigger click no matter I get to site via www.secondpage.com#changefirst or www.secondpage.com

– David
Nov 14 '18 at 10:31













@David check my answer

– ACD
Nov 14 '18 at 10:34





@David check my answer

– ACD
Nov 14 '18 at 10:34













I have some question. 1. is that p tag take time to load on page? 2. you wan to auto click the element when it's available on page?

– Shirish Patel
Nov 14 '18 at 10:44





I have some question. 1. is that p tag take time to load on page? 2. you wan to auto click the element when it's available on page?

– Shirish Patel
Nov 14 '18 at 10:44












2 Answers
2






active

oldest

votes


















1














You're triggers should be inside document ready



$( document ).ready(function() {
if (location.hash === "changefirst")
$('#changefirst').click();
});





share|improve this answer


























  • Thanks for answer but something is wrong with my code above probably and its still not working

    – David
    Nov 14 '18 at 10:40











  • it's working I have to change it like that: $( document ).ready(function() { if (location.hash === "#changefirst") $('#changefirst').click(); });

    – David
    Nov 14 '18 at 10:59



















1














try using



var urlHashVal = window.location.hash;
$("#"+urlHashVal).click();





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53297901%2fafter-click-link-how-to-trigger-onclick-on-another-page-by-id%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    You're triggers should be inside document ready



    $( document ).ready(function() {
    if (location.hash === "changefirst")
    $('#changefirst').click();
    });





    share|improve this answer


























    • Thanks for answer but something is wrong with my code above probably and its still not working

      – David
      Nov 14 '18 at 10:40











    • it's working I have to change it like that: $( document ).ready(function() { if (location.hash === "#changefirst") $('#changefirst').click(); });

      – David
      Nov 14 '18 at 10:59
















    1














    You're triggers should be inside document ready



    $( document ).ready(function() {
    if (location.hash === "changefirst")
    $('#changefirst').click();
    });





    share|improve this answer


























    • Thanks for answer but something is wrong with my code above probably and its still not working

      – David
      Nov 14 '18 at 10:40











    • it's working I have to change it like that: $( document ).ready(function() { if (location.hash === "#changefirst") $('#changefirst').click(); });

      – David
      Nov 14 '18 at 10:59














    1












    1








    1







    You're triggers should be inside document ready



    $( document ).ready(function() {
    if (location.hash === "changefirst")
    $('#changefirst').click();
    });





    share|improve this answer















    You're triggers should be inside document ready



    $( document ).ready(function() {
    if (location.hash === "changefirst")
    $('#changefirst').click();
    });






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 15 '18 at 1:14

























    answered Nov 14 '18 at 10:29









    ACDACD

    8941112




    8941112













    • Thanks for answer but something is wrong with my code above probably and its still not working

      – David
      Nov 14 '18 at 10:40











    • it's working I have to change it like that: $( document ).ready(function() { if (location.hash === "#changefirst") $('#changefirst').click(); });

      – David
      Nov 14 '18 at 10:59



















    • Thanks for answer but something is wrong with my code above probably and its still not working

      – David
      Nov 14 '18 at 10:40











    • it's working I have to change it like that: $( document ).ready(function() { if (location.hash === "#changefirst") $('#changefirst').click(); });

      – David
      Nov 14 '18 at 10:59

















    Thanks for answer but something is wrong with my code above probably and its still not working

    – David
    Nov 14 '18 at 10:40





    Thanks for answer but something is wrong with my code above probably and its still not working

    – David
    Nov 14 '18 at 10:40













    it's working I have to change it like that: $( document ).ready(function() { if (location.hash === "#changefirst") $('#changefirst').click(); });

    – David
    Nov 14 '18 at 10:59





    it's working I have to change it like that: $( document ).ready(function() { if (location.hash === "#changefirst") $('#changefirst').click(); });

    – David
    Nov 14 '18 at 10:59













    1














    try using



    var urlHashVal = window.location.hash;
    $("#"+urlHashVal).click();





    share|improve this answer




























      1














      try using



      var urlHashVal = window.location.hash;
      $("#"+urlHashVal).click();





      share|improve this answer


























        1












        1








        1







        try using



        var urlHashVal = window.location.hash;
        $("#"+urlHashVal).click();





        share|improve this answer













        try using



        var urlHashVal = window.location.hash;
        $("#"+urlHashVal).click();






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 14 '18 at 11:07









        Bhaskara AraniBhaskara Arani

        5221833




        5221833






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53297901%2fafter-click-link-how-to-trigger-onclick-on-another-page-by-id%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Florida Star v. B. J. F.

            Danny Elfman

            Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues