javascript getElementsByClassName() always returns none?

前端 未结 3 671
慢半拍i
慢半拍i 2020-12-10 16:12

I want to create the simplest bookmarklet for my browser.

javascript:document.getElementsByClassName(\'source\').style.visibility=\'visible\';
<
相关标签:
3条回答
  • 2020-12-10 16:47

    You might need to loop through the results, like this:

    var divs = document.getElementsByClassName('source');
    for(var i=0; i<divs.length; i++) { 
      divs[i].style.display='block'
    }
    

    And also as @ionoy mentioned, use display attribute. I hope that helps.

    http://jsfiddle.net/erick/rb7bn/1/

    0 讨论(0)
  • 2020-12-10 16:55

    There is 'visibility' and there is 'display'. They are quite different beasts.

    W3Schools:

    visibility

    display

    0 讨论(0)
  • 2020-12-10 16:59

    Go for display. It's works fine with many browsers and in many cases.

    0 讨论(0)
提交回复
热议问题