Tim Wilkinson Tim Wilkinson - 7 months ago 21
Javascript Question

jQuery works in a test fiddle but not in website

I have this short piece of code that copies content from one div into another on the click of a button:

<a id="btn123">CLICK ME</a>
<div id="test1"></div>
<div id="test2">
<h1>Heading</h1>
</div>

$("#btn1").click(function(){
$('#test1').html($('#test2').contents());
});


This works fine here http://jsfiddle.net/9hnZx/ but when i put it into my website it will not function, anyone know why? Thanks

http://bettondesignwork.co.uk/tim/j3mobile/

Answer

$ is no longer aliased to the jQuery object.

You're explicitly including "jquery-noconflict.js", the only contents of which is jQuery.noConflict();. The explicit intention of this line is to to unalias $ from jQuery.

The following works:

jQuery("#btn1").click(function(){
     $jQuery('#test1').html(jQuery('#test2').contents());
});