admin管理员组文章数量:1312662
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
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
Share
Improve this question
edited Dec 24, 2015 at 20:33
Praveen Kumar Purushothaman
167k27 gold badges213 silver badges260 bronze badges
asked Dec 24, 2015 at 10:30
Arijit MukherjeeArijit Mukherjee
3,8852 gold badges36 silver badges53 bronze badges
1
-
3
Try
$('#MemberCountDiv').find('.MemberDescriptionAdd').attr('id', 'your-new-id');
– Senjuti Mahapatra Commented Dec 24, 2015 at 10:33
2 Answers
Reset to default 6That 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.
本文标签: javascriptChange Id amp Class Inside a variable containing html code jqueryStack Overflow
版权声明:本文标题:javascript - Change Id & Class Inside a variable containing html code jquery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741915227a2404690.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论