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

PREVIOUS NEXT
Code Example
Javascript :: nuxt 3 font awesome 
Javascript :: alertify js vue 
Javascript :: json to string dart 
Javascript :: form validation for email in js 
Javascript :: set id to div element in Javascript 
Javascript :: javascript Set Difference Operation 
Javascript :: upload image postman 
Javascript :: json to pdf javascript 
Javascript :: nginx reverse proxy redirect 
Javascript :: redux toolkit 
Javascript :: yarn globakl 
Javascript :: how to console.log variable in js 
Javascript :: javascript split 
Javascript :: pass data between pages react 
Javascript :: javascript string add new line 
Javascript :: stdout javascript 
Javascript :: model export in node js 
Javascript :: target child event 
Javascript :: passing event handler to useEffeect 
Javascript :: javascript focus on contenteditable not working 
Javascript :: clearinterval javascript 
Javascript :: jsonb_set 
Javascript :: for each array 
Javascript :: react click outside class implementation 
Javascript :: Mqtt js react-native 
Javascript :: how to access data in json format using asp.net c# 
Javascript :: javascript combining arrays 
Javascript :: Substring in Javascript using substr 
Javascript :: callback in react 
Javascript :: loading react 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =