开发者

XHTML valid way to replace text with jquery

开发者 https://www.devze.com 2023-04-01 17:00 出处:网络
I have the following code $(\"#FOO\").hover(function() { $(this).html(\'<p><a href=\"somepage.php\" target=\"_self\">first text</a></p>\');

I have the following code

$("#FOO").hover(function() {
    $(this).html('<p><a href="somepage.php" target="_self">first text</a></p>');
    }, function() {
    $(this).html('<p><a href="somepage.php" target="_self">hovered text</a><开发者_StackOverflow;/p>');
});

Is it improper to put <p> & <a> tags in the .html function? It is invalid XHTML and I'd like to make it cleaner. thanks!

from w3c validator: Error Line 134, Column 83: end tag for element "A" which is not open

the next error is "end tag for element "p" wich is not open. its just reading those tags weird.

….html('<p><a href="somepage.php" target="_self">first text</a></p>');


It's fine. You could use a $("#FOO p") selector if its really bothering you.

0

精彩评论

暂无评论...
验证码 换一张
取 消