Explain width() vs css(‘width’) in JQuery

devquora
devquora

Posted On: Feb 22, 2018

 

In jQuery, there is two way to change the width of an element. One way is using .css(‘width’) and other way is using .width().

For example

$('#mydiv').css('width','300px');
$('#mydiv').width(100);
  • The difference in .css(‘width’) and .width() is the data type of value we specify or return from the both functions.
  • In .css(‘width’) we have to add “px” in the width value while in .width() we don’t have to add.
  • When you want to get the width of “mydiv” element then .css(‘width’) will return ‘300px’ while .width() will return only integer value 300.

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    jQuery Interview Questions

    What is jQuery?

    jQuery is a lightweight JavaScript library which gives a quick and simple method for HTML DOM traversing and manipulati..

    jQuery Interview Questions

    What are the advantages of JQuery ?

    There are many advantages of JQuery. Some of them are :It is more like a JavaScript enhancement so there is no overhea..

    jQuery Interview Questions

    What are the different type of selectors in Jquery?

    There are 3 types of selectors in JqueryCSS Selector XPath Selector Custom Selector..