Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.html() and .append() without jQuery

Can anyone tell me how can I use these two functions without using jQuery?

I am using a pre coded application that I cannot use jQuery in, and I need to take HTML from one div, and move it to another using JS.

like image 560
yeeha1 Avatar asked May 26 '11 08:05

yeeha1


People also ask

How do you append html in html?

HTML code can be appended to a div using the insertAdjacentHTML() method. However, you need to select an element inside the div to add the code. This method takes two parameters: The position (in the document) where you want to insert the code ('afterbegin', 'beforebegin', 'afterend', 'beforeend')

Can we use JavaScript without jQuery?

Don't get me wrong - jQuery is still a wonderful library and most often than not you will be better off using it. However, for smaller things like simple pages with limited JS interactions, browser extensions and mobile sites, you can use vanilla JS.

What is difference between append and html in jQuery?

html() will completely replace the content inside the tag that the selector corresponds to. $('#'). append() will just append to the end of the content inside the tag.

Is append JavaScript or jQuery?

jQuery append() Method The append() method inserts specified content at the end of the selected elements. Tip: To insert content at the beginning of the selected elements, use the prepend() method.


1 Answers

You can replace

var content = $("#id").html(); 

with

var content = document.getElementById("id").innerHTML; 

and

$("#id").append(element); 

with

document.getElementById("id").appendChild(element); 
like image 168
Albireo Avatar answered Oct 14 '22 03:10

Albireo