admin管理员组文章数量:1312782
Is there any way to hide a div from source code at runtime
Using jquery, javascript or any other method.
Eg:
<div id="abc">
This will not be displayed on source as well as in page
</div>
By using jQuery remove()
or hide()
- the item is hidden from front end.
But i need to remove it from source...
I'm using drupal render method.
Is there any way to hide a div from source code at runtime
Using jquery, javascript or any other method.
Eg:
<div id="abc">
This will not be displayed on source as well as in page
</div>
By using jQuery remove()
or hide()
- the item is hidden from front end.
But i need to remove it from source...
I'm using drupal render method.
Share Improve this question edited Oct 17, 2014 at 4:39 ReNiSh AR asked Oct 17, 2014 at 4:33 ReNiSh ARReNiSh AR 2,8522 gold badges33 silver badges43 bronze badges 3- 3 then, why do you include the div? xD – manix Commented Oct 17, 2014 at 4:34
- it will automatically displayed from render method in drupal... – ReNiSh AR Commented Oct 17, 2014 at 4:36
- 1 You're likely attacking the problem from the wrong angle. Since you're using Drupal, look into the hooks system. – jprofitt Commented Oct 17, 2014 at 4:47
5 Answers
Reset to default 6It is not possible to hide DOM elements in browser. You can only remove them using .remove()
or hide with .hide()
when rendered. But if DOM exist in code then you can not hide it in view source code ponent.
Here is one solution
In your body tag add onload event
<body onload='removeDiv()'>
<div id='abc'>
This will not displayed in source code as well as in web page.
</div>
<body>
Javascript
<script>
function removeDiv(){
var div = document.getElementById('abc');
div.remove();
}
</script>
<script>
$('.abc').hide();
</script>
If the .hide() and .remove() doesn't work for you. You can try this. Make a parent div and set the html part empty
<div id="def">
<div id="abc">
This will not be displayed on source as well as in page
</div>
</div>
<script type="text/javascript">
$("#def").html('');
</script>
If you are using drupal the write a php if condition to hide the content of the div, example
<?php if(1){ ?>
<div id="abc">
This will not be displayed on source as well as in page
</div>
<?php }?>
本文标签: javascriptIs there any way to hide a div from source code at runtimeStack Overflow
版权声明:本文标题:javascript - Is there any way to hide a div from source code at runtime - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741898301a2403713.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论