After click link how to trigger onclick on another page by id?
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
|
show 3 more comments
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
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 thatp
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
|
show 3 more comments
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
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
javascript jquery html
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 thatp
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
|
show 3 more comments
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 thatp
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
|
show 3 more comments
2 Answers
2
active
oldest
votes
You're triggers should be inside document ready
$( document ).ready(function() {
if (location.hash === "changefirst")
$('#changefirst').click();
});
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
add a comment |
try using
var urlHashVal = window.location.hash;
$("#"+urlHashVal).click();
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
You're triggers should be inside document ready
$( document ).ready(function() {
if (location.hash === "changefirst")
$('#changefirst').click();
});
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
add a comment |
You're triggers should be inside document ready
$( document ).ready(function() {
if (location.hash === "changefirst")
$('#changefirst').click();
});
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
add a comment |
You're triggers should be inside document ready
$( document ).ready(function() {
if (location.hash === "changefirst")
$('#changefirst').click();
});
You're triggers should be inside document ready
$( document ).ready(function() {
if (location.hash === "changefirst")
$('#changefirst').click();
});
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
add a comment |
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
add a comment |
try using
var urlHashVal = window.location.hash;
$("#"+urlHashVal).click();
add a comment |
try using
var urlHashVal = window.location.hash;
$("#"+urlHashVal).click();
add a comment |
try using
var urlHashVal = window.location.hash;
$("#"+urlHashVal).click();
try using
var urlHashVal = window.location.hash;
$("#"+urlHashVal).click();
answered Nov 14 '18 at 11:07
Bhaskara AraniBhaskara Arani
5221833
5221833
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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