728x90
SMALL
How to change the image with the attr function.
<html>
<img id="imgID" class="imgClass" src="/data/img.png"/>
</html>
<script>
$(document).ready(function(){
//Image change function call
changeIMG();
});
function changeIMG(){
//When changing to the ID of the img tag
$("#imgID").attr("src", "/data/img2.png");
//When changing to class name of img tag
$(".imgClass").attr("src", "/data/img2.png");
}
</script>
It doesn't matter if you change the id value or the class name.
$("#imgID).attr("src","/data/img2.png");
Just remember that phrase.
728x90
LIST
'jQuery' 카테고리의 다른 글
[jQuery] Method / .clone ()-Method to clone selected element (0) | 2022.07.27 |
---|---|
[jQuery] Select all checkboxes, create deselect all (0) | 2022.07.25 |
[jQuery] Create a link that moves smoothly to the top (0) | 2022.07.25 |
[jQuery] Get the horizontal size of the selected element --width, innerWidth, outerWidth (0) | 2022.07.25 |
[jQuery] How to move object to desired position using jquery (0) | 2022.07.22 |