jQuery: 整理4---創建元素和添加元素

1.創建元素:$("內容")

const p = "<p>這是一個p標簽</p>"
console.log(p)console.log($(p))

2. 添加元素

2.1?前追加子元素

1.??指定元素.prepend(內容) ?-> ?在指定元素的內部的最前面追加內容,內容可以是字符串、html標簽或者jQuery對象

    <style>div{margin: 10px 0;}.green {background-color: green;}</style><div class="green"><span>333</span></div>        // 1. 創建一個spanconst span = "<span>666</span>"// 2. 前追加子元素:$(".green").prepend(span)

?

?2.?$(內容).prependTo(指定元素) ? -> 把內容追加到指定元素內部的最前面

    const span2 = "<span>777</span>"$(span2).prependTo($(".green"))

2.2?后追加子元素?

1.?指定元素.append(內容) ?-> ?在指定元素的內部的最后面追加內容,內容可以是字符串、html標簽或者jQuery對象

與前追加子元素一樣,這邊就省略了 -_-

2.3?前追加同級元素

before() ? -> 在指定元素的前面追加內容

 const span2 = "<span>777</span>"$(".blue").before(span2)

?

?

?2.4?后追加同級元素

const span2 = "<span>777</span>"$(".blue").after(span2)

?

注意:將已存在的內容追加到指定元素中: 會將原來元素直接剪切放到指定元素?

?

?

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/377158.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/377158.shtml
英文地址,請注明出處:http://en.pswp.cn/news/377158.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Design a high performance cache for multi-threaded environment

如何設計一個支持高并發的高性能緩存庫 不 考慮并發情況下的緩存的設計大家應該都比較清楚&#xff0c;基本上就是用map/hashmap存儲鍵值&#xff0c;然后用雙向鏈表記錄一個LRU來用于緩存的清理。這篇文章 應該是講得很清楚http://timday.bitbucket.org/lru.html。但是考慮到高…

《MySQL——join語句優化tips》

目錄要不要用joinJoin驅動表選擇Multi-Range Read優化Batched Key Access &#xff08;BKA&#xff09;對NLJ進行優化BNL算法性能問題BNL轉BKA要不要用join 1、如果使用的是Index Nested-Loop Join算法&#xff0c;即可以用上被驅動表的索引&#xff0c;可以用 2、如果使用的…

scala中抽象類_Scala中的抽象類

scala中抽象類抽象類 (Abstract Class) In the Scala programming language, abstraction is achieved using abstract class. 在Scala編程語言&#xff0c; 抽象是使用抽象類來實現的。 Abstraction is the process of showing only functionality and hiding the details fr…

不能catch Fatal的exception

Clemens Vasters - Are you catching falling knives?里給了一個判斷C#的exception是不是fatal的代碼&#xff0c;可以參考參考。 public static bool IsFatal(this Exception exception) {while (exception ! null){if (exception as OutOfMemoryException ! null &&…

HDU 2824 The Euler function

篩法計算歐拉函數 #include <iostream> #include <cstdio> using namespace std; const int maxn3000005; long long phi[maxn]; int main(){int i,j,a,b;for(i1;i<maxn;i) phi[i]i;for(i2;i<maxn;i2) phi[i]/2;for(i3;i<maxn;i2)if(phi[i]i){for(ji;j<…

LinkChecker 8.1 發布,網頁鏈接檢查

LinkChecker 8.1 可對檢查時間和最大的 URL 數量進行配置&#xff1b;當使用 HTTP 請求時發送 do-not-track 頭&#xff1b;生成 XML 的 sitemap 用于搜索引擎優化&#xff1b;檢測 URL 長度和重復的頁面內容&#xff1b;修復了很多檢查的 bug。 LinkChecker 是一個網頁鏈接檢查…

c語言語言教程0基礎_C語言基礎

c語言語言教程0基礎Hey, Folks here I am back with my second article on C language. Hope you are through with my previous article C language - History, Popularity reasons, Characteristics, Basic structure etc. In this one, I will cover some fundamental conce…

《MySQL——臨時表》

內存表與臨時表區別 臨時表&#xff0c;一般是人手動創建。 內存表&#xff0c;是mysql自動創建和銷毀的。 內存表&#xff0c;指的是使用Memory引擎的表&#xff0c;建表語法&#xff1a;create table ... engine memeory 表的數據存在內存里&#xff0c;系統重啟后會被清…

android中ActionBar的幾個屬性

actionBar.setHomeButtonEnabled //小于4.0版本的默認值為true的。但是在4.0及其以上是false&#xff0c;該方法的作用&#xff1a;決定左上角的圖標是否可以點擊。沒有向左的小圖標。 true 圖標可以點擊 false 不可以點擊。 actionBar.setDisplayHomeAsUpEnabled(true) //…

drei

模擬9 T3 &#xff08;COGS上也有&#xff0c;鏈接http://218.28.19.228/cogs/problem/problem.php?pid1428&#xff09; 題目描述 輸入a&#xff0c;p&#xff0c;求最小正整數x&#xff0c;使得a^x mod p 1。 分析 神奇的歐拉定理&#xff08;對于gcd&#xff08;a&#xf…

《MySQL——group by使用tips》

1、如果對group by語句結果沒有排序要求&#xff0c;在語句后面加order by null 2、盡量讓group by 過程用上索引&#xff0c;確認方法是explain結果里沒有Using temporary 和Using filesort 3、如果group by 需要統計的數據量不大&#xff0c;盡量只使用內存臨時表&#xff…

css中變量_CSS中的變量

css中變量CSS | 變數 (CSS | Variables) CSS variables allow you to create reusable values that can be used throughout a CSS document. CSS變量允許您創建可在CSS文檔中使用的可重用值。 In CSS variable, function var() allows CSS variables to be accessed. 在CSS變…

位圖像素的顏色 攜程編程大賽hdu

位圖像素的顏色 Time Limit: 2000/1000 MS (Java/Others) MemoryLimit: 32768/32768 K (Java/Others) Total Submission(s): 0 Accepted Submission(s): 0 Problem Description 有一個在位圖上畫出矩形程序&#xff0c;一開始位圖都被初始化為白色&#xff08;RGB顏色表示…

《MySQL——InnoDB與Memory以及臨時表》

InooDB與Memory 數據組織方式不同&#xff1a; InnoDB引擎把數據放在主鍵索引上&#xff0c;其他索引上保存的是主鍵id。為索引組織表Memory引擎把數據單獨存放&#xff0c;索引上保存數據位置。為堆組織表 典型不同處&#xff1a; 1、InnoDB表的數據總是有序存放的&#x…

Oracle 用戶 profile 屬性 轉

--查看profile 內容 select * from dba_profiles where profilePF_EAGLE; --查看用戶的profiles select username,profile from dba_users; --查看是否啟用動態資源限制參數 SHOW PARAMETER RESOURCE_LIMIT; --啟用限制 ALTER SYSTEM SET RESOURCE_LIMITTRUE SCOPEBOTH; --創建…

CUL8R的完整形式是什么?

CUL8R&#xff1a;稍后再見 (CUL8R: See You Later) CUL8R is an abbreviation of "See You Later". CUL8R是“稍后見”的縮寫 。 It is an expression, which is commonly used in messaging or chatting on social media networking sites like Facebook, Yahoo M…

SuperSpider——打造功能強大的爬蟲利器

SuperSpider——打造功能強大的爬蟲利器 博文作者&#xff1a;加菲 發布日期&#xff1a;2013-12-11 閱讀次數&#xff1a;4506 博文內容&#xff1a; 1.爬蟲的介紹 圖1-1 爬蟲&#xff08;spider) 網絡爬蟲(web spider)是一個自動的通過網絡抓取互聯網上的網頁的程序&#xf…

《MySQL——關于grant賦權以及flush privileges》

先上總結圖&#xff1a; 對于賦予權限或者收回權限還是創建用戶&#xff0c;都會涉及兩個操作&#xff1a; 1、磁盤&#xff0c;mysql.user表&#xff0c;用戶行所有表示權限的字段的值的修改 2、內存&#xff0c;acl_users找到用戶對應的對象&#xff0c;將access值修改 g…

對Spring的理解

1、Spring實現了工廠模式的工廠類&#xff0c;這個類名為BeanFactory實際上是一個接口&#xff0c;在程序中通常BeanFactory的子類ApplicationContext。Spring相當于一個大的工廠類&#xff0c;在其配置文件中通過<bean>元素配置用于創建實例對象的類名和實例對象的屬性。…

Java中的null是什么?

As we know null is an important concept in every language not only in Java but here we will study various factors regarding null. 我們知道null在每種語言中都是重要的概念&#xff0c;不僅在Java中&#xff0c;在這里我們還將研究有關null的各種因素。 null is a ver…