Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

jQuery - Add Elements

//append()
$("p").append("Some appended text.");

//prepend() 
$("p").prepend("Some prepended text.");

//after()
$("img").after("Some text after")

//before()
$("img").before("Some text before");

//Add Several New Elements With append() and prepend()
function appendText() {
  var txt1 = "<p>Text.</p>";               // Create element with HTML 
  var txt2 = $("<p></p>").text("Text.");   // Create with jQuery
  var txt3 = document.createElement("p");  // Create with DOM
  txt3.innerHTML = "Text.";
  $("body").append(txt1, txt2, txt3);      // Append the new elements
}

//Add Several New Elements With after() and before()
function afterText() {
  var txt1 = "<b>I </b>";                    // Create element with HTML 
  var txt2 = $("<i></i>").text("love ");     // Create with jQuery
  var txt3 = document.createElement("b");    // Create with DOM
  txt3.innerHTML = "jQuery!";
  $("img").after(txt1, txt2, txt3);          // Insert new elements after <img>
}
Comment

add jquery

$(".demo").prepend("Yo!");          // adds content at the beginning in the selected elements
$(".demo").append("<em>Hey!</em>"); // adds content at the end in the selected elements
$(".demo").before("Cheers");        // adds content before the selected elements
$(".demo").after("<em>Peace</em>"); // adds content after the selected elements
Comment

PREVIOUS NEXT
Code Example
Javascript :: react native diasble view 
Javascript :: regex for not accepting zeros 
Javascript :: onchange radio button jquery ajax 
Javascript :: how to create a class javascript 
Javascript :: how to get json response from rest api in node js 
Javascript :: how manipulate the multiple input option data in one function in vue js 
Javascript :: jquery datatable update row cell value 
Javascript :: how to get variable from url in javascript 
Javascript :: datatables and toggle not working 
Javascript :: tricky javascript interview questions 
Javascript :: array with object same keys 
Javascript :: if or react 
Javascript :: javascript formate date 
Javascript :: jquery add css important 
Javascript :: usehistory() hook 
Javascript :: encodeuricomponent reverse 
Javascript :: change class js 
Javascript :: get previous link javascript 
Javascript :: parsedate javascript 
Javascript :: axios delete request 
Javascript :: where is select value in javascript event object 
Javascript :: Promise.all() with async and await 
Javascript :: javascript reflection 
Javascript :: numero aleatorio javascript 
Javascript :: byte to integer js 
Javascript :: greater than x but less than y js 
Javascript :: react redux not updating 
Javascript :: npm react-syntax-highlighter 
Javascript :: javascript function 
Javascript :: arrow function javascript 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =