Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [JavaScript][CSS]Jak dostać się do wartości atrybutu klasy?
stellatus
post 10.03.2020, 12:09:37
Post #1





Grupa: Zarejestrowani
Postów: 196
Pomógł: 0
Dołączył: 9.03.2017

Ostrzeżenie: (0%)
-----


Nie mogę tego nigdzie znaleźć. Jak dostać się do wartości atrybutu klasy? Np. chciałbym dostać się do wartości column-count w .newspaper:

https://www.w3schools.com/Css/tryit.asp?fil...s3_column-width

Kod
<style>
.newspaper {
  column-count: 3;
  column-width: 100px;
}
</style>
</head>
<body>

<div class="newspaper">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum.
</div>


Go to the top of the page
+Quote Post
nospor
post 10.03.2020, 12:14:21
Post #2





Grupa: Moderatorzy
Postów: 36 455
Pomógł: 6292
Dołączył: 27.12.2004




Chcesz w js dostac sie do stylu elementu?

https://zellwk.com/blog/css-values-in-js/


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
trueblue
post 10.03.2020, 12:15:25
Post #3





Grupa: Zarejestrowani
Postów: 6 761
Pomógł: 1822
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


https://developer.mozilla.org/en-US/docs/We...etComputedStyle


--------------------
Go to the top of the page
+Quote Post
stellatus
post 10.03.2020, 12:41:08
Post #4





Grupa: Zarejestrowani
Postów: 196
Pomógł: 0
Dołączył: 9.03.2017

Ostrzeżenie: (0%)
-----


Wpisałem to do konsoli:
Kod
let para = document.querySelector('.newspaper');
let compStyles = window.getComputedStyle(para);
compStyles.getPropertyValue('column-count')


i pojawia się błąd: Argument 1 of Window.getComputedStyle is not an object.
Go to the top of the page
+Quote Post
nospor
post 10.03.2020, 12:50:59
Post #5





Grupa: Moderatorzy
Postów: 36 455
Pomógł: 6292
Dołączył: 27.12.2004




No ale gdzie ty to dales? Bo widac wyraznie ze nie znalazl elementu wiec pewnie to dales zanim DOM sie wygenerowal. To masz dac po wygenerowaniu DOM (html) a nie przed


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
stellatus
post 10.03.2020, 13:01:58
Post #6





Grupa: Zarejestrowani
Postów: 196
Pomógł: 0
Dołączył: 9.03.2017

Ostrzeżenie: (0%)
-----


OK. Wszystko działa. Dzięki bardzo!

https://codepen.io/rudolph-reti/pen/WNvdaqX
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 25.04.2024 - 11:31