Get Class name and set attribute - Javascript Object

Javascript examples for Object:Object Operation

Description

Get Class name and set attribute

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//from   ww  w .j  a  v  a  2s  . c  om
var anchorArr = document.getElementsByTagName("a");
for (var i = 0; i < anchorArr.length; i++) {
    if(anchorArr[i].getAttribute("class")==="videoimage") {
        console.log(anchorArr[i].getAttribute("data-id"));
    }
}
    }

      </script> 
   </head> 
   <body> 
      <a href="#" class="videoimage" data-id="ks3H_s3e-Wc"></a>  
   </body>
</html>

Related Tutorials