Click here to Skip to main content
12,070,171 members (29,712 online)
Rate this:
 
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 20: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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web03 | 2.8.160208.1 | Last Updated 2 Apr 2013
Copyright © CodeProject, 1999-2016
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