0

I want to change the JavaScript function

function changediv(div1, div2) {
   div1.obj.innerHTML = div2.obj.innerHTML;
}

by something like this

function changediv(div1,div2) {
   $('#div1').html() = $('#div2').html();
}

to take advantage of jQuery. Can you help me with the correct syntax? Thanks in advance.

3
  • 2
    How are those divs being submitted to the function? As HTML Objects? IDs? Something else? Commented Nov 23, 2011 at 23:22
  • Hi Benjam. The divs are submitted as IDs. Commented Nov 23, 2011 at 23:28
  • Rocket, div1.obj.innerHTML is the content of <div id="div1">...</div>. Commented Nov 23, 2011 at 23:40

3 Answers 3

4
function changediv(div1,div2) {
   $(div1.obj).html($(div2.obj).html());
}

In your 1st example, I'm assuming div1.obj is your DOMElement. If not, you'll need to fix the selector yourself, but to set the innerHTML in jQuery you do:

$('sel').html('str');
Sign up to request clarification or add additional context in comments.

1 Comment

This alternative is better for me because I can continue to use the function changediv. Thank you very much.
3

something like

var html_dev1 = $('#div1').html();
$('#div2').html(html_dev1);

1 Comment

The function is passed args div1 and div2. There's no evidence that the actual ids of the divs are these values. That's why the selector should be $(div1) not $('#div1')
0

this will replace the value of div1 to be like div2

 $(document).ready(function() {
     $('#div1').html($('#div2').html());
 });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.