Click here to Skip to main content
11,707,470 members (76,454 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript PHP jQuery
i have two page on is test1.html and test2.html



on test1.html contain code >>
Quote:
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("#test").click(function(){
$("p:last").removeClass("intro").addClass("main");
});
});
</script>
<style type="text/css">
.intro
{
color:red;
}
.main
{
background-color:yellow;
}
</style>
</head>
<body>

<a href="test2.html" id="test">go to next</a>

</body>
</html




and on test2.html >>
Quote:
Quote:
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("#test").click(function(){
$("p:last").removeClass("intro").addClass("main");
});
});
</script>
<style type="text/css">
.intro
{
color:red;
}
.main
{
background-color:yellow;
}
</style>
</head>
<body>

This is a paragraph.



</body>
</html




now when i click on go to next then page will be redirected to test2.html

then on test2.html page intro class rename with main class (
Posted 1-Apr-13 19:11pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

1. $("#test").click event on the second page will not be fired as it the element is not in the test2.html
2. $("#test").click event on the first page will have no effect as the element p is not in the first page.

3. So the javascript or jquery works only for the page it belongs to not for other pages.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Mika Wendelius 220
1 Maciej Los 195
2 OriginalGriff 148
3 Sergey Alexandrovich Kryukov 145
4 chainerlt 110
0 OriginalGriff 9,198
1 Sergey Alexandrovich Kryukov 8,562
2 CPallini 5,189
3 Maciej Los 4,921
4 Mika Wendelius 3,856


Advertise | Privacy | Mobile
Web01 | 2.8.150819.1 | Last Updated 2 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100