I am am trying to append an element to a <div>
of a page, but it is not working.
Page1 (index.php)
<a href=" another.php " id="p1id" type="button">Go to page 2</a>
Page2 (another.php)
<div id=p2id></a>
JavaScript (jqtest.js)
$.("#p1id").click(function(){
$.("#p1id").append()
});
<div>
tag with </a>
. That's invalid. Also, just calling the append
method with no argument is meaningless - FishBasketGordo 2012-04-05 20:56
the problem
$.("#p1id").click(function(){
-^here
$.("#p1id").append()
--^ here
});
remove the .
try this:
<div id="p2id"></div>
...
$("#p1id").click(function(event){
$("#p1id").append();
event.preventDefault();
return false;
});
In addition:
append
something<a/>
, as a button. You will need to prevent the default action, which would be to load a page.You're also calling append()
with no arguments. It needs a content
argument.
If your html is
<div id="p1id">A div<div>
You can append like
$(function(){
$('#p1id').click(function(e){
var myP=$('<p class="myClass">New paragraph</p>');
$(this).append(myP);
});
});
An example is here.
.
between$
and your selector, for starters - Mathletics 2012-04-05 20:55