Why html element created on fly is unable to use appendTo method ?
Please view this code:
<script type="text/javascript">
$
(function(){
$
("<p>Hi all</p>").appendTo($("p img"))
})
</script>
I am just trying to add a newly created P element to another P element that contains images with the help of appendTo() method. But i am getting this error:
Unexpected call to method or property access.
Can you please tell me why this is happening ? It is against the documentation in jQuery official web site.As you can see it is clearly written there:
With .appendTo(), on the other hand, the content precedes the method,
either
as a selector expression or as markup created on the fly,
and it is inserted into the target container.
Thanks