Get the App
SLTechnology News&Howtos  ›  Development  › 

Can jquery add attributes to the picture?

Shulou Source: shulou.com Published: 2022-05-31 17:08:58 10月13日 Update

This article mainly introduces whether jquery can add attributes to the picture of the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, with a certain reference value, I believe you can read this jquery whether you can add attributes to the picture article will have a harvest, let's take a look.

Jquery can add attributes to pictures. Two ways to add attributes: 1, use attr () to add attributes to img elements, syntax "$(" img "). Attr (" attribute name "," value ")"; 2, use prop () to add attributes to the picture element, syntax "$(" img ") .attribute (" attribute name "," value ")".

The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.

There are two ways to set properties in jquery

Attr ()

Prop ()

1. Use attr ()

The attr () method sets or returns the properties and values of the selected element.

When this method is used to set property values, one or more attribute / value pairs are set for matching elements.

$("img") .attr ("attribute name", "attribute value")

Example:

$(document) .ready (function () {$("button") .click (function () {$("img"). Attr ("align", "right");})

Add an align attribute to the picture to set the right alignment

2. Use prop ()

The prop () method, like attr (), sets or returns the properties and values of the selected element.

When this method is used to set attribute values, one or more attribute / value pairs are set for a collection of matching elements.

Syntax:

$("img") .prop ("attribute name", "attribute value")

Example:

$(document) .ready (function () {$("button") .click (function () {$("img"). Prop ("alt", "alternative text of the image");})

Add an alt attribute to the picture

Extended knowledge: picture element img

The tag defines the image in the HTML page.

Tags have two required attributes: src and alt.

Attributes of the tag:

Attribute value description aligntop

Bottom

Middle

Left

RightHTML5 does not support it. HTML 4.01 is obsolete. Specifies how images are arranged according to the surrounding text. Loadingeager: load now

Lazy: delayed loading specifies whether the browser should load the image immediately or delayed. Alttext specifies the alternate text for the image. BorderpixelsHTML5 does not support it. HTML 4.01 is obsolete. Specifies the border around the image. Crossoriginanonymous

Use-credentials sets the cross-domain property of the image heightpixels specifies the height of the image. HspacepixelsHTML5 does not support it. HTML 4.01 is obsolete. Specifies the white space on the left and right side of the image. Ismapismap defines the image as a server-side image mapping. LongdescURLHTML5 does not support it. HTML 4.01 is obsolete. Point to the URL that contains a long image description document. SrcURL specifies the URL that displays the image. Usemap#mapname defines an image as a client-side image mapping. VspacepixelsHTML5 does not support it. HTML 4.01 is obsolete. Specifies the white space at the top and bottom of the image. Widthpixels specifies the width of the image. This is the end of the article on "whether jquery can add attributes to pictures". Thank you for reading! I believe you all have a certain understanding of the knowledge of "whether jquery can add attributes to pictures". If you want to learn more knowledge, you are welcome to follow the industry information channel.

Tags: Attributes images pictures elements methods support but not knowledge text tags grammar content multiple examples blank article delay two value right Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Huawei Linux MariaDB vpn