最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - js addclass function not working as expected, intereaction or special WP somethign needed?

programmeradmin1浏览0评论

I am having an issue adding a class via jsto an existing html set up. If I inspect, it simply doesnt show up. It doesnt add it. I have it on a delay to ensure everything is done loading. I have also set a console.log message just to ensure that the function is running and it is.

It does not show in the console as even having been added. Is there something below that is specific to wordpress that is interfering? The example below works on its own but not in its environment.

What am I doing wrong here?

function classadd() {
      window.setTimeout(function () {

        var ideal = document.getElementById( 'test' )
        var parent = document.getElementById('t_options')
        if(ideal){
          parent.classList.add('black');
          console.log('running');
        } else {
          console.log('uh-oh');
        }
      },7000); 
    }
    
  classadd();
    .black{background:black!important;}
<div id="t_options" class="some_classes">
      <div id="test">
        some content
      </div>
    </div>

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论