Get the App
SLTechnology News&Howtos  ›  Development  › 

How JavaScript changes HTML Images

Shulou Source: shulou.com Published: 2022-06-01 10:54:35 10月12日 Update

This article mainly introduces JavaScript how to change the HTML image, the article is very detailed, has a certain reference value, interested friends must read it!

JavaScript: reaction to events

Example

Click me!

The alert () function is not commonly used in JavaScript, but it is very convenient for code testing.

The onclick event is just one of many events that you will learn in this tutorial.

JavaScript: changing the content of HTML

Using JavaScript to process HTML content is a very powerful feature.

Example

X=document.getElementById ("demo"); / / find the element

X [XSS _ clean] = "HelloJavaScript"; / / change the content

You will often see document.getElementById ("someid"). This method is defined in HTMLDOM.

DOM (DocumentObjectModel) (document object Model) is the official W3C standard for accessing HTML elements.

You will learn about HTMLDOM in several chapters of this tutorial.

JavaScript: changing HTML ima

This example dynamically changes the source of the HTML (src):

Light up the light bulb

Function changeImage ()

{

Element=document.getElementById ('myimage')

If (element.src.match ("bulbon"))

{

Element.src= "/ images/pic_bulboff.gif"

}

Else

{

Element.src= "/ images/pic_bulbon.gif"

}

}

Tags: Content images events middle schools elements examples tutorials knowledge articles power code value regular meetings interests functions functions dynamic just multiple objects Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Shulou Tech Info MySQL vpn Shulou Technology