Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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 solution

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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900