Reputation: 1362
I am using JQuery to take the text in all labels and add it to the input's placeholder. I am deliberately leaving the <strong>
text alone.
I have it working great in Firefox and Chrome, but in IE it stops before the last step of the first label. How can I make this work in IE?
JQuery:
$("li label").each(function() {
var label = $(this);
var placeholder = label.contents().get(0).nodeValue;
label.closest("li").find("input").attr("placeholder", placeholder).val("").focus().blur();
label.contents().get(0).remove();
});
Example HTML:
<li>
<label for="field-1">My Label<strong>required</strong></label>
<input id="field-1" type="text">
</li>
Upvotes: 0
Views: 1453
Reputation: 388316
.get(index) returns the dom element reference of the element in the passed index, so label.contents().get(0).remove();
calls the dom element's remove method(Supported only on Edge)
Use .eq() to get the jQuery element reference and then call the remove() method
label.contents().eq(0).remove();
Upvotes: 5