Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery.html() returns invalid IMG [duplicate]

Tags:

jquery

xhtml

Possible Duplicates:
Jquery html() and self closing tags
Is it expected that jQuery $('span').html() turns XHTML br tag to html syntax?

I have a document like this

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script src="/js/core/jquery.js" type="text/javascript"></script>
</head>
<body>
    <div id="content">
        <img src="/some/image.gif" />
    </div>
</body>
</html>

I want to retrive html for some nodes to do something. But I see one problem with IMG.

$('#content').html();

This returns invalid XHTML

<img src="/some/image.gif">

jQuery version is 1.4.2.

like image 446
Anton Egorov Avatar asked Nov 05 '10 00:11

Anton Egorov


1 Answers

This is a duplicate, but none of the answers in the original question gives an actual workaround. (Probably rightly so. I can't but agree with what @Cletus says in his - as always excellent - answer.)

But if you're stuck with XHTML: there is a jQuery plugin providing a innerXHTML() function (poorly maintained though, last updated 2007, and never made it from Beta) and a JavaScript tool named innerXHTML that promises to do what you need. If you need this, that may be your best bet.

like image 56
Pekka Avatar answered Oct 24 '22 13:10

Pekka