Find all html characters in drop-down option text and replace them via jQuery
Posted
by
Jon Harding
on Stack Overflow
See other posts from Stack Overflow
or by Jon Harding
Published on 2012-06-15T15:13:40Z
Indexed on
2012/06/15
15:16 UTC
Read the original article
Hit count: 229
I have a dropdown menu that pulls in text from a database column. The database column can include HTML mark-up. In the drop-down I obviously don't need that in the text. I am working on some jquery and it partially accomplished what I'm looking for. However, it seems to only be replacing the first instance of each character
$('select option').each(function() {
this.text = this.text.replace(' ', ' ');
this.text = this.text.replace('<div>', '' );
this.text = this.text.replace('</div>', '' );
});
Here is the HTML for the drop-down:
<select name="ctl00$SubPageBody$ClassList" id="ctl00_SubPageBody_ClassList">
<option value="196">Four Week Series: July 19, 2012, 11:00am-12:00pm&<div>July 26, 2012, 11:00am-12:00pm </div><div>August 2, 2012, 11:00am-12:00pm</div><div>August 9, 2012, 11:00am-12:00pm</div></option>
</select>
© Stack Overflow or respective owner