Javascript examples for Object:Object Operation
Get Class name and set attribute
<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>