Check if Div with specific Class exists in the page

后端 未结 3 1901
闹比i
闹比i 2021-01-27 20:09

I\'m trying to modify an existing webpage by inserting my own Javascript file in it. I\'m setting a background Image for this webpage by inserting a new Div through my Javascrip

3条回答
  •  孤独总比滥情好
    2021-01-27 21:07

    document.addEventListener("DOMContentLoaded", function() {
      var ie = document.getElementsByClassName("ie");
      if(ie.length > 0) {
        alert("It's IE!");
      }
    }
    

    This should answer your first question, although I agree that there are better solutions for your overall goal.

提交回复
热议问题