javascript - How to handle failed JQuery DOM conversion -


i have common function display errors result of ajax call. of messages html strings, want convert dom object search elements inside using .find(). others strings (not html). in case, don't know how handle this...it generating exceptions.

var messagetest = "" + this; if ($(messagetest).length == 0) {     message += this; } else {     message += $(messagetest).find('.message-error').html(); } 

fyi, "this" in case seems string object array in each item character, in inspector, isn't showing "my message here" but:

[0]: "m" [1]: "y" 

etc

when string, not html, error @ if statement line:

uncaught error: syntax error, unrecognized expression:<the contents of messagetext> 

so how gracefully handle when input html string or string?

note...in end, want string, going wrap in it's own html.

if it's either string or html, can appended element, , sorted out:

var msg = $('<div />').append(this),     err = msg.find('.message-error'),     txt = err.length ? err.text() : msg.text();  message += txt; 

append string or html empty div, if div contains .message-error element, text of element, otherwise text of div, equal original string etc.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -