E
E
Evgeny Zhurov2017-06-13 15:49:43
PHP
Evgeny Zhurov, 2017-06-13 15:49:43

How to check if an element has a specific parent?

Good afternoon, tell me, please. There is this static markup:

<div>
  <a href="1.png">
    <img src="1.png">
  </a>
  <a href="2.png">
    <img src="2.png">
  </a>
  <img src="3.png">
</div>


That is, there are three pictures, two of them are wrapped in links. You need to write code that checks that each picture of this block has a parent with the "a" tag. If some image does not have such a parent, then it is wrapped in "a" and the src of the image is assigned as href. I know how to wrap, and how to assign href. The main thing that is needed is a check for the existence of a parent with the given "a" tag. How to do it? In order not to re-wrap images in links that are already wrapped in them.

Answer the question

In order to leave comments, you need to log in

6 answer(s)
S
Stanislav Shendakov, 2018-10-24
@kuzmenkodiman

Use PDO

V
Vadim, 2018-10-24
@kylt_lichnosti

Given that you have saved it to the database, and not executed, there is already some kind of protection there.
And if on business, then use prepared statements and PDO.

S
Stimulate, 2018-10-24
@Stimulate

Screen incoming data.

U
Uno, 2018-10-24
@Noizefan

If I were a doctor of technical sciences, I would recommend you a permanent indefinite ip ban for these script-kids, from nerves, so to speak =)
Catching them with the words SELECT, UPDATE or INSERT in the incoming data is not difficult.

O
oldpyron, 2018-10-25
@oldpyron

I agree with the previous guys - if the connector is self-written, then you need to screen the data included in the request. But, IMHO, to escape not words, but symbols for sql: semicolon, single and double quotes and something else - because I had it for a long time, and it's easy to google.

I
Igor Peregudov, 2017-06-13
@igorperegudov

$('a+img')?
or even better $('div > a') and then wrap

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question