Find all html characters in drop-down option text and replace them via jQuery
- by Jon Harding
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>