javascript - Why can't my code set attributes on elements?
習慣沉默
習慣沉默 2017-05-19 10:45:09
0
3
506
    <h1 class="MyClass">一</h1>
    <script>
        var hs =document.getElementsByTagName('h1');
        alert(hs[0].className);
        hs[0].className='XXXX';
    </script>

This is this code. Why can't I set a new value for this tag? setAttribute() doesn't work either.

習慣沉默
習慣沉默

reply all(3)
给我你的怀抱

Is there any interference from other h1 tags? I can use your code to test it and it’s fine

给我你的怀抱

Are these the only codes? It should be fine. . .

漂亮男人

Can be set.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template