Using the Johann Burkard inc: A super-tiny client-side include JavaScript jQuery plugin with onclick works but I have not been unable to change it into an href with direct Javascript code:

<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="http://johannburkard.de/resources/Johann/jquery.inc-5.js"></script>
</head>
<body>
<p onclick="$(this).inc('inc_me.html');">1) Paragraph with onclick</p>
<a href="javascript:$(this).inc('inc_me.html');">2) Href with javascript</a>
</body>
</html>

What I Did and What It Did:

When clicking on the first paragraph its content is replaced by the contents of inc_me.html. When clicking on the second paragraph nothing changes.

What I Expected:

I expected the second paragraph to be replaced in the same way that the first one was.

What is the jQuery way to get this passed to $()?

I am using Google Chrome 5.0.307.11 beta.

2 answers

0
points
<p id="p2"></p><a id="a2" href="javascript:$('#p2').inc('inc_me.html');$('#a2').empty();">2) Href with javascript</a>
Answered over 6 years ago by C.W.Holeman II
Mottie 1134
0
points

I didn't do a lot of digging into the code, but I think to make it work with the code in the href you may have to change the plugin.

There are two other ways to call the script though that will work:

<a href="#" onclick="$(this).inc('inc_me.html');return false;">Href with javascript</a><br>

or

<a class="p2" href="#">Href with javascript</a>
<script type="text/javascript">
$(document).ready(function(){
 $('.p2').click(function(){
  $(this).inc('inc_me.html');
  return false;
 })
})
</script>
Answered over 6 years ago by Mottie