javascript - How to create an 'onclick' function? -


i want create 'onclick' function. able youtube. add function when click on gray field, container moves right 50% width. fill div text , pictures. sorry bad english, hope guys understand want

.news {  position: fixed;  display: block;  width: 33.33%;  height: 100%;  float: left;  background-color: grey;;  background-size: auto, cover;  transition: width 0.5s;  }    .open{  width: 50%;  transition: width 0.5s;  position: fixed;  display: block;  width: 50%;  height: 100%;  float: left;  background-color: grey;  background-size: auto, cover;  }
<!doctype html>  <html>  <head>      <meta charset="utf-8">      <link rel="stylesheet" href="css/reset.css">      <link rel="stylesheet" href="css/style.css">        <script>      function toggleclass (el) {                    if(el.classname == "news"){  		el.classname = "open";  	} else {  		el.classname = "news";  	}                }  </script>        </head>    <body>      <div class="news" onclick="toggleclass(this)"></div>  </body>  </html>

you can use innerhtml property can add text

el.innerhtml = 'text' 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -