admin管理员组文章数量:1404923
I would like to hide the div (which is "hide-div") as soon as the user cliks on the button when there is a navigation to the same page. Please help me on this. Thanks
<div id="hide-div">
<button type="button" title="test" class="button btn-small" onclick="setLocation('abc');"><span>'Add to Cart'</span></button>
</div>
I would like to hide the div (which is "hide-div") as soon as the user cliks on the button when there is a navigation to the same page. Please help me on this. Thanks
<div id="hide-div">
<button type="button" title="test" class="button btn-small" onclick="setLocation('abc.');"><span>'Add to Cart'</span></button>
</div>
Share
Improve this question
edited Sep 10, 2015 at 12:35
m4n0
32.4k28 gold badges80 silver badges96 bronze badges
asked Sep 10, 2015 at 12:18
KumarKumar
1791 silver badge7 bronze badges
4
- Please follow below link stackoverflow./questions/14648439/… – Suman Singh Commented Sep 10, 2015 at 12:21
-
In
setLocation
addgetElementById('dide-div').setAttribute('style','display:none;');
– nelek Commented Sep 10, 2015 at 12:21 - use localStorage to preserve the value and base on the value show/hide the div .. – Kishore Sahasranaman Commented Sep 10, 2015 at 12:22
- can you please edit above i don't understand. Sorry – Kumar Commented Sep 10, 2015 at 12:23
5 Answers
Reset to default 3Using Vanilla JavaScript. Although I remend using event handler instead of inline JS, this is in view of your code.
- Hide the element using
style.display
- You can redirect the page after hiding the button using
window.location
function setLocation(loc) {
document.getElementById('hide-div').style.display = 'none';
window.location = loc;
}
<div id="hide-div">
<button type="button" title="test" class="button btn-small" onclick="setLocation('http://google.')"><span>'Add to Cart'</span></button>
</div>
You can do this by simple jquery
<script>
jQuery(document).ready(function($) {
$(".button").click(function(){
$("div").fadeOut();
});
});
</script>
Using jQuery you can do this in your onclick:
$('#hide-div').hide()
http://api.jquery./hide/
Use jQuery to hide it:
$('#hide-div button').click(function(){
$(this).parent().hide();
});
I assume you have jQuery added to your page already. So, something like this maybe:
$('#hide-div .button').on('click', function() {
$('#hide-div').hide();
});
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="hide-div">
<button type="button" title="test" class="button btn-small" onclick="setLocation('abc.');"><span>'Add to Cart'</span></button>
</div>
本文标签: javascriptHow to hide div after clicking on buttonStack Overflow
版权声明:本文标题:javascript - How to hide div after clicking on button? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744877475a2630003.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论