I have added a label in Jquery
$('[id$="refAprtyAppId"]').after('<label class="error" id="refAprtyAppIdError">Error: Referral Id is required.</label>');
I have tried
$('[id$="refAprtyAppId"]').parent().find("label#refAprtyAppIdError").remove();
to remove the label, but it is failed to remove.
Html is
<div class="area">
<input id="refAprtyAppId" value="" styleClass="externalAppId referralId"/>
</div>
Whats the problem here?
I have added a label in Jquery
$('[id$="refAprtyAppId"]').after('<label class="error" id="refAprtyAppIdError">Error: Referral Id is required.</label>');
I have tried
$('[id$="refAprtyAppId"]').parent().find("label#refAprtyAppIdError").remove();
to remove the label, but it is failed to remove.
Html is
<div class="area">
<input id="refAprtyAppId" value="" styleClass="externalAppId referralId"/>
</div>
Whats the problem here?
Share asked Dec 14, 2017 at 11:32 NeoCoderNeoCoder 1011 silver badge8 bronze badges 3- This code works just fine. Are you sure you have included jQuery? – Master Yoda Commented Dec 14, 2017 at 11:34
- Your code works fine: jsfiddle/bxddmfj4. Please check the console for errors. – Rory McCrossan Commented Dec 14, 2017 at 11:35
- Thank you guys. There was an error referencing the jquery library. Thanks again. Now it is solved. – NeoCoder Commented Dec 16, 2017 at 5:36
3 Answers
Reset to default 6Why don't you use id selector. You have an id there. Use it.
$('#refAprtyAppIdError').remove();
As per the html documentation you are allowed to have multiple id with same name on the same page. If you have multiple "error label" then you can use -
$('label.error').remove();
Adding answer to better clarify my ment.
Your code works fine:
$('[id$="refAprtyAppId"]').after('<label class="error" id="refAprtyAppIdError">Error: Referral Id is required.</label>');
$('#remove').on('click', function() {
$('[id$="refAprtyAppId"]').parent().find("label#refAprtyAppIdError").remove();
});
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="area">
<input id="refAprtyAppId" value="" styleClass="externalAppId referralId" />
</div>
<button type='button' id='remove'>Remove Label</button>
Check the JavaScript console in your browser for other errors. Its possible that jQuery has not been referenced correctly.