V
V
Vadim Stepanenko2020-05-14 12:17:26
JavaScript
Vadim Stepanenko, 2020-05-14 12:17:26

Hang up onclick on certain pictures?

From the api, I get the html markup of the task (for school). This markup can contain both small pictures (for example, formulas, calculations) and large ones (graphs, maps, etc.).

You need to somehow parse the resulting html, get images with a width > 200 (conditionally) and hang onClick on them somehow, but I don’t quite understand how this can be implemented. Maybe someone faced similar?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
drawnofmymind, 2020-05-14
@drawnofmymind

let's say:

<img src="https://m.buro247.ru/images/senina/SpongeBob_stock_art.jpg.webp" alt="" class="hi">
<img src="https://m.buro247.ru/images/senina/SpongeBob_stock_art.jpg.webp" alt="" class="g">
<img src="https://m.buro247.ru/images/senina/SpongeBob_stock_art.jpg.webp" alt="" class="hi">

.hi{
  width:200px;
  height: 200px;
  border: 1px solid red;
}
.g{
  width:100px;
  height: 200px;
  border: 1px solid red;
}

document.querySelectorAll('img').forEach((item)=>{
  if(item.offsetWidth == 200){
  		item.setAttribute("onclick", "func")
  }
  console.log(item) 
})

0
0xD34F, 2020-05-14
@0xD34F

You need to somehow parse the resulting html ...

Not necessary.
Make a delegate handler where it will check who the target element is, and if it's an image, also check its size.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question