JQuery-.css () not working for input

This should be a really simple problem, but I cannot understand what I'm doing wrong. I am trying to access the CSS property "border-bottom" as follows:

var temp = $('#divName').css('border-bottom'); 

Unfortunately, after this temp contains the string ""

Does anyone know why this is not working or what should I do differently to make it function? Thanks.

+6
source share
3 answers

Styles should be more specific. Since border-bottom is a short property for other properties (similar to background , to name a generic one), the property must be explicitly set.

 var elem = $('#divName'); var border_width = elem.css('border-bottom-width'); var border_color = elem.css('border-bottom-color'); var border_style = elem.css('border-bottom-style'); var border_bottom = border_width + " " + border_color + " " + border_style; 

Fiddle: http://jsfiddle.net/6wRj4/
See Also: MDN: border-bottom short-hand .

+8
source

Make sure $ ('# divName') selects one item. You can use the array syntax for the jquery object to return the underlying DOM object. You should also check (for example, using Firebug) to make sure that the DOM element you are looking for has the style you are looking for.

If both of these things work correctly, you can try using more granular border properties ... border-bottom-style, border-bottom-width, etc.

+2
source

Try with document.getElementById("divName").style.borderBottom; .

0
source

Source: https://habr.com/ru/post/900967/


All Articles