Chris Weems Chris Weems - 6 months ago 15
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>
</div>


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, "");
$('label').html(r);
});


Here is the jsfiddle I have been trying it on: https://jsfiddle.net/32rch0n9/1/

Thanks for any help/suggestions

Answer
Reference: [https://jsfiddle.net/32rch0n9/5/][1]

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


  [1]: https://jsfiddle.net/32rch0n9/5/