Cannot read property 'style' of undefined — Uncaught Type Error

前端 未结 2 509
没有蜡笔的小新
没有蜡笔的小新 2021-02-13 14:49

I would like to change the color, fontsize and font weight of the text in a span element of the html page.

I am using the following code:

if(window.locat         


        
2条回答
  •  既然无缘
    2021-02-13 15:29

    It's currently working, I've just changed the operator > in order to work in the snippet, take a look:

    window.onload = function() {
    
      if (window.location.href.indexOf("test") <= -1) {
        var search_span = document.getElementsByClassName("securitySearchQuery");
        search_span[0].style.color = "blue";
        search_span[0].style.fontWeight = "bold";
        search_span[0].style.fontSize = "40px";
    
      }
    
    }

    Search results for "hi".

提交回复
热议问题