Jquery adds image borders

02-06-2024

1. create a new HTML project and introduce jquery into the project;

<script type="text/javascript" src="/static/jquery-2.1.4.min.js"></script>

2. After introducing jquery, add an image using img tags in the project for testing purposes;

<img src="images/1.jpg" />

3. After adding the image, create a button and bind it with an onclick click event for clicking to add borders;

<button onClick="set()"><button>

4. Finally, after adding the button, obtain the image object through the tag name in the click event, and use the css() method to add the border attribute to the image;

function set(){$('img').css("border","2px solid red");}


Copyright Description:No reproduction without permission。

Knowledge sharing community for developers。

Let more developers benefit from it。

Help developers share knowledge through the Internet。

Follow us