Check out bidbear.io Amazon Advertising for Humans. Now publicly available 🚀

jQuery: Modifiers

Contents

Here are some notes and examples on some of the most common jQuery modifiers:

.text()

This is very similar to the vanilla JS .textContent property. The full documentation for .text() is here.

It will either retrieve the text content of the selected element or change it if you add new text in the brackets. So for example:

this is the first h1 on this doc

Now if I want to change the first h1 we can pass the text that we would like into the .text method:

changing the text

.html()

This works just like the vanilla JS method .innerHTML. Meaning that we will return all of the html in the selected tag, not just the text content. We can also replace all of the html. jQuery docs are available for this here.

.attr()

jQuery Docs Here.

Allows you to get and set the attributes of an object, for example changing the alt text on an image.

.attr() takes two arguments, a getter and a setter. If you do not use the second argument it will simply return the current value of the requested attribute. For example

$("img").attr("src")

Will return the current source of the selected image. But if you use the second attribute:

$("img").attr("src","https://www.ngoughlin.com/image2.jpg")

Will change whatever the image src was to this new image hosted on my website. This changes the picture.

Amazon Ad Analytics For Humans

Advertising reports automatically saved and displayed beautifully for powerful insights.

bidbear.io
portfolios page sunburst chart