Reduce jQuery append method Is this the simplest way to write this? This code evaluates if a textbox value exceeds 20 characters, and then displays the proper message (essentially truncating the string and then adding an ellipses to the end.)

I've tried using a tertiary operator but doesn't seem to work with appending data to an element as it overwrites what was previously appended.)

if (searchBoxValue.length &gt; numCharToDisplay) {
    searchDropDown.append('&lt;div class="noresults"&gt;&lt;span&gt;Searching "' +
    searchBoxValue.trim().substring(0, numCharToDisplay) +
    '..." Found No Results&lt;/span&gt;&lt;/div&gt;');
} else {
    searchDropDown.append('&lt;div class="noresults"&gt;&lt;span&gt;Searching "' +
    searchBoxValue.trim() + '" Found No Results&lt;/span&gt;&lt;/div&gt;');
}
Instead of writing append two times, why don't append a single time with two different values depending on the length of searchBox?

Also, moving the trimmed search value into a variable simplifies the code a bit.

var text,
    trimmedSearch = searchBoxValue.trim();
if (searchBoxValue.length &gt; numCharToDisplay) {
    text = '&lt;div class="noresults"&gt;&lt;span&gt;Searching "' +
    trimmedSearch.substring(0, numCharToDisplay) +
    '..." Found No Results&lt;/span&gt;&lt;/div&gt;';
} else {
    text = '&lt;div class="noresults"&gt;&lt;span&gt;Searching "' +
    trimmedSearch + '" Found No Results&lt;/span&gt;&lt;/div&gt;';
}
searchDropDown.append(text);


Using ternary operators, as you suggested, wouldn't be a good practice since it complicates things up, leaving maintenance really difficult.