如果页面中存在元素,则触发代码执行

时间:2017-02-27 09:12:25

标签: javascript jquery

我有下面的javascript:

$(document).on('click', '#layer_cart .cross, #layer_cart .continue, .layer_cart_overlay', function(e){
    e.preventDefault();
    $('.layer_cart_overlay').hide();
    $('#layer_cart').fadeOut('fast');                
    location.reload();
});

我想用location.reload创建if语句。如果系统在源代码中找到#divforexample,则重新加载页面。我想我需要使用

elem = document.getElementById("divforexample ");

或者我错了?谢谢你的帮助。

在线:https://jsfiddle.net/wu7qqns0/#&togetherjs=bI8oGhhQB4

为我解决了:

var x = document.getElementById("reload");
            if (x){
                location.reload();                    
            }

1 个答案:

答案 0 :(得分:0)

Dashboard
相关问题