6/16/2011

How to change css padding property using javascript dynamically

Using Javascript we can change css value. Here I have written how to change the value of padding top, padding bottom, padding left, padding right differently. var ab = 20;
//To change Padding-top value write document.getElementById("div_Id").style.paddingTop = ab.toString()+"px" //To change Padding-left value write document.getElementById("div_Id").style.paddingLeft = ab.toString()+"px" //To change Padding-right value write document.getElementById("div_Id").style.paddingRight = ab.toString()+"px" //To change Padding-bottom value write document.getElementById("div_Id").style.paddingBottom = ab.toString()+"px"

2 comments:

  1. Thanks sir it lot of help me my search ends here
    can u tell the same in jquery how we use it

    ReplyDelete
    Replies
    1. Jquery is very easy.
      var ab = 20px;
      jQuery(document).ready(function(){
      jQuery("#div_Id").css("padding", ab);
      });

      Delete