[英]when i am using javascript function to get elemen by class it shows me [object HTMLCollection] not the value inside the div
I have also convert the variable s to string but the result is same what to do how to get the value by class.我还将变量 s 转换为字符串,但结果与如何按类获取值相同。
function myFunction() {
var s = document.getElementsByClassName('clinic-timings-day');
alert(s);
document.getElementById('#mine').innerHTML = s[0].toString();
alert("test2");
}
<body>
<p class="clinic-timings-day">MON, WED</p>
<a onclick="myFunction()">Try it</a>
</body>
Your made few mistakes on your function.您在功能上犯了一些错误。
var s = document.getElementsByClassName('clinic-timings-day').innerHTML;
document.getElementById('mine').innerHTML = s[0].toString();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.