Skip to content Skip to sidebar Skip to footer

Hide Text But Not Input Inside A Label Jquery

I have a label and input outputted from the shopping cart we are using. I don't want to hack the core of the cart to change the way it outputs. So the code is thus with the input i

Solution 1:

Replace the labels contents with just the checkbox.

var l = $('label[for=FormField_29_0]');
l.html(l.find('input'));

Solution 2:

This works, but there is probably a better way:

var$label = $("label[for='FormField_29_0']");
var$checkbox = $label.find("input:checkbox");
$label.html($checkbox);

Edit

Since you're removing the text, I guess you can replace the label with just the checkbox:

var$label = $("label[for='FormField_29_0']");
$label.replaceWith($label.find("input:checkbox"));

Edit

Or, if you want to leave the text in place, but just hide it (again, I'm sure there's a better way):

var$label = $("label[for='FormField_29_0']");
var$text = $('<span>' + $label.text() + '</span>').hide();
var$checkbox = $label.find("input:checkbox");
$label.empty().append($checkbox).append($text);

Solution 3:

var$formfield = $('#FormField_29');
$formfield.find('label').html($formfield.find('label input'));

Solution 4:

I think your problem has to do with the fact that your input is nested inside your label tag. Using the altered html below you should be able to alter the label's text with any number of selectors such as $('.FormField label').text('');

    <div id="FormField_29" class="FormField">
    <label for="FormField_29_0">Yes</label><input type="checkbox"id="FormField_29_0" name="FormField[2][29][0]" value="Yes" class="subscribeBox FormFieldOption"  />
</div>

Solution 5:

using jquery you could remove the input element from the label, prepend it to the label (adding it back in), and then hide the label.

http://docs.jquery.com/Manipulation/remove#expr

Post a Comment for "Hide Text But Not Input Inside A Label Jquery"