你所在的位置: 首页 > 正文

Seven Most Common jQuery Methods Part One: Text() and HTML()

2019-08-09 点击:1518
fg游乐电子美人捕鱼

  The course introduced seven most common jQuery methods that can save us a lot of time and make our code super clean.

  1. .text()

  2. .html()

  3. .attr()

  4. .val()

  5. .addClass()

  6. .removeClass()

  7. .toggleClass()

  Today, I am going to share the first two methods study note with you.

  I start to create a simple HTML page includes h1, an simple input and a fruit list.

  2204783-bbbfa2cea5877fff.JPG

  Then, I link to the jQuery file and check if it is connected correctly.

  2204783-8c63877d7e222b38.JPG

  .text()

  According to?jQuery,this method can get combined text contents of each element in the set of matched elements, including their descendants, or set the text contents of the matched elements.

  For example, if I want to see the h1 text content in console, I just need to type?$(“h1”).text(). Then, it will call back the h1 text.

  2204783-79e846b655c4c594.JPG

  We can do the same thing to the list content, too. When I select the li, it will return all list items in a string.

  2204783-2355b5bb821bc72d.JPG

  text() method can also change the content. I can change the h1 text content by adding the new content inside the text().

  2204783-bca15451445dce6a.JPG

  .html()

  According to?jQuery,it allows to get the HTML contents of the first element in the set of matched elements or set the HTML contents of every matched element.

  If I want to see the HTML of the list, I can type$(“ul”).html().It will return the HTML content.

  2204783-b606c8dd77b5c429.JPG

  If I want to update the HTML list, we can enter the new HTML list in the html(). I updated the list from three items to two items.

  2204783-d40739c39d9104a0.JPG

达到当天最大量
fg电子和mg电子平台秤 版权所有© www.grasper24.com 技术支持:fg电子和mg电子平台秤 | 网站地图