There is a function that changes the value of the id block to "block", initially it is hidden, the value is none

function show(p) { document.getElementById("p").style.display = "block"; } 

The problem is that the value changes, if instead of p you directly write an id block ("name2"), can you somehow transfer it to a function and use it safely?

Function call itself

 <p onclick="show("name2")">ΠŸΡ€ΠΈΠΌΠ΅Ρ€ тСкста</p> 

    1 answer 1

    Your problem is that you have incorrect HTML and because of this the onclick event does not work:

     <p onclick="show("name2")">ΠŸΡ€ΠΈΠΌΠ΅Ρ€ тСкста</p> 

    Quotes must be escaped.
    Just give the correct options:

     <p onclick="show(\"name2\")">ΠŸΡ€ΠΈΠΌΠ΅Ρ€ тСкста</p> <p onclick="show('name2')">ΠŸΡ€ΠΈΠΌΠ΅Ρ€ тСкста</p> <p onclick='show("name2")'>ΠŸΡ€ΠΈΠΌΠ΅Ρ€ тСкста</p> <p onclick='show(\'name2\')'>ΠŸΡ€ΠΈΠΌΠ΅Ρ€ тСкста</p> 

    The most convenient practice is to use one type of quotes in HTML, and another in JavaScript.

    After correcting the error

     function show( p ) { document.getElementById( p ).style.display = "block"; } 

    will work successfully.


    PS I lied. The most convenient practice is to place events on markup elements. Like this:

     $( "p" ).on( "click", show ); 

    But it is only later, when you finally understand the basics;)

    • Thank you so much! As soon as I did not try to pass the parameters, I forgot about the shielding. - Dmitriy