What I'm Trying to Do is On click of AddMore Button I'm Getting id of the button
<div id="MemberCountDiv">
<div class="MemberDescriptionAdd" style="display:none;">
<select name="MemberCountType" id="MemberCountTypeX" class="MemberCountTypeX form-control ">
<option selected="selected" value="">Condition</option>
<option value="<">Less Than (≤)</option>
<option value=">">Greater Than (≥)</option>
<option value="=">Equal</option>
</select>
<select name="MemberCount" id="MemberCountX" class="MemberCountX form-control ">
<option selected="selected" value="">Members</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="8">7 Or More Than 7</option>
</select>
<button id="RemoveX" class="btn btn-blue" type="button">Remove</button>
</div>
</div>
I have kept this div and what I'm On click is
$(".AddMoreButton").click(function () {
var type = $(this).val();
var idname = $(this).attr("id");
var id = idname.replace("AddMore", "");
alert(id);
var adddiv = $('#MemberCountDiv').html();
alert(adddiv);
adddiv.find('.MemberDescriptionAdd').attr('id', 'your-new-id');
alert(adddiv);
});
What I'm trying to do is append id to the id and the class
Error:
adddiv.find is not function
That is beacause adddiv is html string and not jquery object of element. use:
var adddiv = $('#MemberCountDiv');
alert(adddiv.html());
adddiv.find('.MemberDescriptionAdd').attr('id', 'your-new-id');
alert(adddiv.html());
You cannot do these using string. Just use .clone()
:
var adddiv = $('#MemberCountDiv').clone();
alert(adddiv.html());
adddiv.find('.MemberDescriptionAdd').attr('id', 'your-new-id');
alert(adddiv.html());
Now adddiv
acts as a HTML Element and you can make all the changes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With