Chris Weems Chris Weems - 5 months ago 11x
Javascript Question

jQuery Remove Brackets/Text from Label

Here is a snippet of HTML that loads on the site, I cannot change this as it's loaded via code blocks in 3D Cart:

<div class="opt-field">
<label for="text56">4kg - $19 [+$19.00]</label>
<input type="text" size="3" name="text56" value="0"><br>

<label for="text58">8kg/18lb - $29 - Currently Out of Stock [+$29.00]</label>
<input type="text" size="3" name="text58" value="0"><br>

<label for="text59">12kg/26lb - $39 - Currently Out of Stock [+$39.00]</label>
<input type="text" size="3" name="text59" value="0"><br>

And I want to remove the automatically generated [+$price] that is attached to each label. I have tried many variations I have found on here but nothing seems to affect it.

$(document).ready(function() {
var str = $('.opt-field label');
var r = str.replace(/[(\[].*?[)\]] */g, "");

Here is the jsfiddle I have been trying it on:

Thanks for any help/suggestions

Reference: [][1]

Your regular expression works. The catch is you have to apply for each label. Refer to the above fiddle for sample.