How can I get an element by ClassName with a launch with a specific string?

I need to get an element by ClassName that starts with:

width-48 height-48 profile_view_img

Full tag:

<div class="width-48 height-48 profile_view_img_9131256"></div>

Rooms of this class are always changing.

This is what I have tried so far:

var x = window.document.querySelectorAll("*[class^=\"width-48 height-48 profile_view_img\"]")[0]
+4
source share
4 answers

Try the following:

var x = window.document.querySelectorAll("*[class^=\"width-48 height-48 profile_view_img\"]")[0]
var className = x.className;

JSFiddle .

+3
source

You can use querySelectoras follows:

var element = document.querySelector(".width-48.height-48.profile_view_img");

Or just use getELementsWithClassone that accepts such spaces:

var elements = document.getElementsByClassName("width-48 height-48 profile_view_img");
+1
source

.

Try:

var x = document.querySelectorAll('.width-48.height-48.profile_view_img')[0];

:

X - , .width-48 AND .height-48 AND .profile_view_img.

0

first, ,

width-48 height-48 profile_view_img

you can try:

var x = window.document.querySelectorAll("*[class^='width-48'] *[class^='height-48'] *[class^='profile_view_img']")[0]
-1
source

All Articles