Using the following code I can change the name of the button when user hovers over it. Is there a way to change the button's name with its id when user hovers over it (using JavaScript)?
.button:hover span { display: none }.button:hover:before { content: "New name"; }.button:hover { background-color: #aaaaaa; }
<button class="button" id="some_id"> <span>old name</span> </button>
You can use attr(id)
. See the documentation for further information.
.button:hover span { display: none }.button:hover:before { content: attr(id); }.button:hover { background-color: #aaaaaa; }
<button class="button" id="some_id"> <span>old name</span> </button>
Here's one that changes things back...
onmouseover="this.innerHTML=this.id;"
onmouseout="this.id=this.innerHTML; this.innerHTML='old name';"
Just add these events to the button.
Quite easy actually...
onmouseover="this.innerHTML=this.id;"
Just add this event to the button.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.