2

I would like to put a <div id="all_content"> element into <sector id="all_field"> element with Javascript

<section id="all_field"></section>
<div id="all_content">
    <h1>---&nbsp;&nbsp;Meeting Room Booking&nbsp;&nbsp;---</h1>
    <fieldset class="box"><legend class="booking_meetRom">Approved Status of Meeting</legend>
        <div><a>More Detail</a> </div>
    </fieldset>
    <fieldset class="box"><legend class="booking_meetRom">123</legend>
        <div>123</div>
    </fieldset>
</div>

Here is JSFIDDLE: http://jsfiddle.net/Y6MpQ/

It should be like this:

<section id="all_field">
<div id="all_content">
    <h1>---&nbsp;&nbsp;Meeting Room Booking&nbsp;&nbsp;---</h1>
    <fieldset class="box">
        <legend class="booking_meetRom">Approved Status of Meeting</legend>
        <div><a>More Detail</a> </div>
    </fieldset>
    <fieldset class="box">
        <legend class="booking_meetRom">123</legend>
        <div>123</div>
    </fieldset>
</div>
</section>

JSFIDDLE should be: http://jsfiddle.net/Y6MpQ/1/

5 Answers 5

3

Try to use .append() in this context,

$('#all_field').append($('#all_content'));

DEMO

Sign up to request clarification or add additional context in comments.

4 Comments

That's great :-) Thank you very much. Do you think that <section> element will work with IE 8? If not, is there any others element for changing?
@PMay1903 No.. its a kind of html5 tag. only ie >= 9 will support html 5.
@PMay1903 <div> should be a great alternative for <section> like tags.
It's awesome. I have changed <section> to <div> and it worked as before with IE=8. Thanks again :-).
2

With Jquery you can use append

$html = '<div id="all_content">';
$html += '<h1>---&nbsp;&nbsp;Meeting Room Booking&nbsp;&nbsp;---</h1>';
$html += '<fieldset class="box">';
$html += '<legend class="booking_meetRom">Approved Status of Meeting</legend>';
$html += '<div><a>More Detail</a> </div>';
$html += '</fieldset>';
$html += '<fieldset class="box">';
$html += '<legend class="booking_meetRom">123</legend>';
$html += '<div>123</div>';
$html += '</fieldset>';
$html += '</div>';

$('#all_content').append($html);

3 Comments

This will throw error. proper concatenation should be applied.
why would you use the dollar sign for variable declaration?
That is OK. Thank you for your code but there is something that needs you to change :-)
2

Using pure JavaScript:

var field = document.getElementById('all_field');
var content = document.getElementById('all_content');

field.innerHTML = content.outerHTML;
content.remove();

See the working code at:

JSFiddle

2 Comments

Thank you for your comment. This might work well. However, Do you think that it might not be optimized as minimum as Rajaprabhu Aravindasamy's method?
This is a pure JS solution, no JQuery is needed. For some folks, this is considered the bare minimum solution :)
1
$("#all_content").prependTo("#all_field")

jsfiddle http://jsfiddle.net/guest271314/sjMqL/

Comments

0

Try:

document.getElementById("all_field").innerHTML = "<div id="all_content">";

or JQuery:

$("#all_field").html("<div id="all_content">");

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.