Home>

Pay attention to the html markup, I'm interested in how to set the onclick element correctly. Made three options, they all work. Due to the fact that I recently started learning JS, I cannot figure out which of these options is more literate.

function one () {
alert ('Do you like, what you see?')
}
function two () {
alert ('1000-7')
}
let three= document.querySelector ('. block3');
three.onclick= function () {
alert ('It gets bigger, when i pull on it');
} 
.block1 {
margin-top: 10px;
padding: 10px;
border: 3px solid black;
}
.block2 {
margin-top: 10px;
padding: 10px;
border: 3px solid black;
}
.block3 {
margin-top: 10px;
padding: 10px;
border: 3px solid black;
} 
<
div class= "block1" onclick= "one ()" >
 Option 1 <
/div >
  <
! -1 option ->
<
div class= "block2" onclick= two () >
 Option 2 <
/div >
  <
! -option 2 ->
<
div class= "block3" >
 Option 3 <
/div >
                   <
! -option 3 ->

what is the difference between 1 and 2?

Алексей Шиманский2021-10-15 02:57:11

In fact, none of the options are correct (in the modern world)

Алексей Шиманский2021-10-15 02:57:11

What should you use? Surfacing?

Хмельни́цький2021-10-15 02:57:11

you can have it. in general, listeners are now hung via addEventListener. Whether to use delegation or not is already the tenth thing.

Алексей Шиманский2021-10-15 02:57:11

so what's the difference between options 1 and 2?

Алексей Шиманский2021-10-15 02:57:11