Skip to content Skip to sidebar Skip to footer

Issue While Setting Html Of Div Using The Jquery Html() Method

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:

Solution 1:

Perhaps you should enclose with double quotes:

<a href=\"javascript:sendDirectMessage('1711838', 'abc')\">

Solution 2:

  1. The HTML you are trying to generate is invalid (this is your primary problem). Since you are using XHTML, the rules for quoting attributes are simple: attribute values must be quoted. Yours are not.
  2. You are using JavaScript: pseudo URIs
  3. You are using invalid XHTML
  4. You are not using HTML-Compatible XHTML

Solution 3:

Try this:

$('#results').html('<div class="tweet"><a href="javascript:sendDirectMessage(\'1711838\', \'abc\')">DM</a><hr/></div>');

Solution 4:

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(
"<divclass='tweet'><ahref=\"javascript:sendDirectMessage('1711838', 'abc')\">DM</a><hr/></div>"
);

The \" creates a " inside a double-quoted string.

Solution 5:

As Aito says, you need double quotes:

$('#results').html("<divclass='tweet'><ahref=\"javascript:sendDirectMessage('1711838', 'abc')\">DM</a><hr/></div>");

Post a Comment for "Issue While Setting Html Of Div Using The Jquery Html() Method"