Kadzhaev Marat
Kadzhaev Marat

Reputation: 1317

jQuery outerHTML close tag

I'm using jQuery for get outer html: $('.page')[0].outerHTML and this works, but I have img tags which must be closing like this: <img src="smth" /> but outerHTML delete /. How solve this problem?

UPD: Well, I still have not found a solution. How get outer html without changes?

Upvotes: 4

Views: 351

Answers (1)

Bhojendra Rauniyar
Bhojendra Rauniyar

Reputation: 85545

This is not really a problem. But browser strips out the closing tag. Even if you manually use <img src="path.jpg"> it renders correctly in the page. Though the coding practice is to use closing tags for such elements.

Have you ever noticed even if you have typed <img src="path.jpg" /> the browser just shows the <img src="path.jpg"> when you inspect it.

So, you don't need to be worry about this.

Upvotes: 4

Related Questions