简体   繁体   English

显示元素后执行 Function

[英]Perform Function After Element Is Revealed

I'm working on a website where a div tag reveals itself after enough products are selected.我正在一个网站上工作,在该网站上选择了足够多的产品后会显示一个 div 标签。 What I'm trying to do is add an ID to this div tag after it's revealed using javascript.我要做的是在使用 javascript 显示此 div 标签后添加一个 ID。

This is the tag that's revealed:这是显示的标签:

<div class="discount-summary"></div>

This is the javascript I've created:这是我创建的 javascript:

$(".discount-summary").load($(this),function(){
   addDiscount();
});

function addDiscount() {
            $('.discount-summary').attr('id','discountbox');
}

Unfortunately, this does not appear to be working.不幸的是,这似乎不起作用。

Updated更新

Try:尝试:

<div class="discount-summary">Just a test</div>
$( document ).ready(function() {
    setInterval(addDiscount, 1000)
});

function addDiscount() {
    $('.discount-summary').attr('id','discountbox');
}

CodePen代码笔

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM