+ 1
how to change elements with onclick
how to use js to replace elements by others when clicked on a button , and how to replace elements with inputted ones
5 Respostas
+ 3
document.querySelector("Element").addEventListener('click', function(){
What to do when the element is clicked
});
If the element is class don't forget the "." Before the class name
If it's I'd don't forget the "#"
If it's a tag just put it's name
But Note the element should be in quote
+ 1
That's should help u started maybe, but be more specific pls
+ 1
<style>
.paintred {color="red";}
</style>
<div id="mydiv">
my element </div>
<button onclick="myfunction()">
click me
</button>
<script>
function myfunction() {
var el = getElementById('mydiv');
el.setAttribute('class', 'paintred');
</script>
0
What do you mean by "replace elements by others"? what is this "others"?
Also what do you mean by "replace elements with inputted ones"? what is inputted? how this input is read?
Please rephrase the Description and if possible add examples what to replace, which replaces what etc. Hopefully with clearer description more people will come to respond.
Good luck! 👍
0
<input type="buttob" onclick = "test()">
function test() {
console.log("it works");
}