简体   繁体   中英

Are there deeper conditions in jquery for assigning css values of classes to variables? It doesn't work with all classes I would like

It often works to assign as mentioned in title, for example:

var a1 = $('.entry--menu .btn.entry--link').css('left');

When I execute alert(a1) it shows me the assigned value of the property left of the class .entry--menu .btn.entry--link

But there are other cases where it doesn't work, for example:

var a2 = $('.last-seen-products .product--box .product--image .image--element').css('width');

When I execute alert(a2) , it shows null .

I tried different things in order to find out why - for example I assigned in the css file at the top the following: width:100px But nothing works.

Is there something that I overlook? Are there requirements, for example something like (a fictitious) requirement that the class must have the property position:absolute or something similar??

it "works" for me if you separate the classes by ","

var a2 = $('.last-seen-products, .product--box, .product--image, .image--element').css('width');

but it returns the last value it founds in the last class where it founds it... I mean if:

.last-seen-products{ width: 100px; }
.image--element{ width: 10px }
.product--image{ width: 500px }

it will return "10px" because is the last class in the list... hope it helps.

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