Dynamically create elements of jQuery - html(), $()

Table of contents

1. html()

1. Obtain content: html() method does not give parameters

2. Set content

Two, $()


1. html()

1. Obtain content: html() method does not give parameters

$('#div').html()

2. Set content

  • The content includes tags, which will be parsed out
$('#div').html('我是<a href="www.baidu.com">百度一下</a>')

Two, $()

// 确实能创建元素,但是创建的元素只能存在于内存中,如果在页面上显示,需要追加
var a = $('<a href="www.baidu.com">百度一下</a>')
// 追加节点
$('#div').append(a)

Guess you like

Origin blog.csdn.net/qq_52421092/article/details/131248030