1

I am just trying to load the content of one div into another onClick, but i get an error requesting i use the POST request,

$("#button").click(function(){
     $('#slide1').load('#slide2');
});

half working example at http://jsfiddle.net/9hnZx/

Still new to the whole jQuery front so please be patient if this is a stupid question! Thanks!

edit. Thanks to all who answered, really helped, except the example i gave is working in jsfiddle but i cant get working in the website where it is required, http://bettondesignwork.co.uk/tim/j3mobile/ anyone got any clues? jQuery is loading just fine!

Tim Wilkinson
  • 3,761
  • 11
  • 34
  • 62

4 Answers4

1

Try:

$("#button").click(function(){
    $('#slide1').html($('#slide2').html());
});
1

Other answers suggest copying the HTML of one element to another. This is a bad idea, for the reasons illustrated in this answer. Instead, copy the DOM elements:

$("#button").click(function(){
    $('#slide1').html($('#slide2').contents());
});

For documentation on this, see the API reference pages for html and contents

Community
  • 1
  • 1
lonesomeday
  • 233,373
  • 50
  • 316
  • 318
0

try instead

 $("#button").click(function(){
         $('#slide1').html($('#slide2').html());
    });
Cris
  • 12,799
  • 5
  • 35
  • 50
0

jQuery Code

$("#button").click(function(){
         //first get the send div text
        var secondDiv = $("#slide2").text();
        var firstDiv = $("#slide1").text();
         // slide 1 value

         $('#slide2').text(secondDiv+" "+firstDiv);
    });
Waqas Ghouri
  • 1,079
  • 2
  • 16
  • 36
  • surely this will only put text from one div into another? when used in its intended application it will be taking lots more content other than just text. – Tim Wilkinson Feb 01 '13 at 13:52