Reputation: 615
I've got an issue with jquery where I set the html of a div using the html method, but it does not set it correctly.
Here's the stripped down code I'm using:
<?xml version='1.0' encoding='utf-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script language="javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js" type="text/javascript"></script>
<script type='text/javascript'>
jQuery(document).ready(function($) {
$('#results').html("<div class='tweet'><a href=javascript:sendDirectMessage('1711838', 'abc')>DM</a><hr/></div>");
})
</script>
</head>
<body>
<div id="results"/>
</body>
</html>
but when I view the result in the generated page using firebug, the element has it's contents set to:
<a )="" abc="" href="javascript:sendDirectMessage('1711838',">DM</a>
What am I doing wrong??
Upvotes: 0
Views: 194
Reputation: 17132
As Aito says, you need double quotes:
$('#results').html("<div class='tweet'><a href=\"javascript:sendDirectMessage('1711838', 'abc')\">DM</a><hr/></div>");
Upvotes: 0
Reputation: 943579
Upvotes: 2
Reputation: 887449
You forgot to quote your href
attribute.
Therefore, it stopped parsing the href
's value after the first space.
You need to write the following:
$('#results').html(
"<div class='tweet'><a href=\"javascript:sendDirectMessage('1711838', 'abc')\">DM</a><hr/></div>"
);
The \"
creates a "
inside a double-quoted string.
Upvotes: 0
Reputation: 1038850
Try this:
$('#results').html('<div class="tweet"><a href="javascript:sendDirectMessage(\'1711838\', \'abc\')">DM</a><hr/></div>');
Upvotes: 1
Reputation: 6872
Perhaps you should enclose with double quotes:
<a href=\"javascript:sendDirectMessage('1711838', 'abc')\">
Upvotes: 2