1

I have a table that carries out some AJAX actions, an returns an error if one is encountered.

I'm using JS to insert this error (which is a string), but because the string has HTML tags in it, it's being appended at the end of the JS element where I wish it to be inserted, as opposed to in the middle.

var debug_error = '<span class="debug-message hidden">'+table_obj.debug_string+'</span>',
    row =         $(id+' .row-debug'); // id is definded

row.html(debug_error);

For example, if debug_string was <h3>Error</h3><p>Please define an email address</p>, my results are -

<span class="debug-message hidden"> </span>
<h3>Error</h3>
<p>Please define an email address</p>

Yet if I remove the HTML tags, an use just ErrorPlease define an email address, it works as expected -

<span class="debug-message hidden">ErrorPlease define an email address</span>

Does any body know why this is happening? Thanks.

1
  • It's illegal to put a H3 in a span element. Commented Aug 7, 2013 at 11:36

1 Answer 1

4

The problem is because it's not valid to put a block level element, such as h3, inside an inline element, such as span. Make the span into a div and it should work:

var debug_error = '<div class="debug-message hidden">' + table_obj.debug_string + '</div >',
    row = $(id + ' .row-debug'); // id is definded    
row.html(debug_error);

If needed, you can make the div appear inline (and thus behave like the span did) using CSS:

.debug-message {
    display: inline;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Bingo, that did the job. Thanks for sharing the knowledge.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.