简体   繁体   中英

Javascript Remove specific attribute from style

Hello i have started to learn Javascript and i was wondering if there is a way to remove a specific attribute from the style here is an example that explain what i mean

  <div id="divbrd" style="width:500px; height:350px; border:1px solid #000; box-shadow:10px 5px 10px #777;"></div>

this is a div tag with a style so if i want to remove the box-shadow from the style attribute how can i do this here is what i have done :

<script type="text/javascript">
    var   div_brd = document.getElementById("divbrd");
    div_brd.removeAttribute("style","box-shadow");
    </script>

correct me please ... thanks

Try this

<script type="text/javascript">
var   div_brd = document.getElementById("divbrd");
div_brd.style.boxShadow = "none";
</script>

Fiddle:

In this fiddle there is box shadow on div but it's removing from js

以防万一,如果您还想学习jQuery。

$('#divbrd').css("box-shadow", "");

this will remove the attribute

<script type="text/javascript">
var   div_brd = $("#divbrd");
div_brd.style.boxShadow = "none";
</script>

OR

<script type="text/javascript">
     $('#divbrd').css("box-shadow", "none");
    </script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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