Setting title attribute with Javascript function

后端 未结 3 1211
逝去的感伤
逝去的感伤 2021-01-04 09:12

I am trying to find, if I can pass a value on the title attribute of a label element using Javascript?

I have tried the following Javascrip

3条回答
  •  渐次进展
    2021-01-04 09:13

    Try this way:-

    HTML:

    JS:

    window.onload = function() {
        document.getElementById('lab').setAttribute('title','mytitle');
        alert(document.getElementById('lab').title);
    }​
    

    Refer LIVE DEMO

提交回复
热议问题