admin管理员组文章数量:1323714
Hi I have multiple elements with the same structure in my application. Second div element's id varies as per the ment id in the db which is unique. There are elements with the id 'vote_up' and 'vote_down'. This gets repeated for each ment.What happens is that, as I mentioned, there are multiple ments. I want to perform an Ajax request. First of this structure functions properly using ajax, but the rest does an http request. Btw I am developing a rails application and I am using jQuery.
<div id="post_ment">
john<i> says </i> Comment<br/>
<div id="ment_10_div">
**<form action="/ments/vote_up" id="vote_up" method="post">**
<div style="margin:0;padding:0;display:inline">
<input name="authenticity_token" type="hidden"
value="w873BgYHLxQmadUalzMRUC+1ql4AtP3U7f78dT8x9ho=" />
</div>
<input id="Comment_place_id" name="Comment[post_id]" type="hidden" value="3" />
<input id="Comment_id" name="Comment[id]" type="hidden" value="10" />
<input id="Comment_user_id" name="Comment[user_id]" type="hidden" value="2" />
<input name="mit" type="submit" value="Vote up" />
</form>
<label id="ment_10">10</label>
**<form action="/ments/vote_down" id="vote_down" method="post">**
<div style="margin:0;padding:0;display:inline">
<input name="authenticity_token" type="hidden"
value="w873BgYHLxQmadUalzMRUC+1ql4AtP3U7f78dT8x9ho=" />
</div>
<input id="Comment_place_id" name="Comment[place_id]" type="hidden" value="3" />
<input id="Comment_id" name="Comment[id]" type="hidden" value="10" />
<input id="Comment_user_id" name="Comment[user_id]" type="hidden" value="2" />
<input name="mit" type="submit" value="Vote Down" />
</form>
</div>
Can you please help me to solve this Thanks
Hi I have multiple elements with the same structure in my application. Second div element's id varies as per the ment id in the db which is unique. There are elements with the id 'vote_up' and 'vote_down'. This gets repeated for each ment.What happens is that, as I mentioned, there are multiple ments. I want to perform an Ajax request. First of this structure functions properly using ajax, but the rest does an http request. Btw I am developing a rails application and I am using jQuery.
<div id="post_ment">
john<i> says </i> Comment<br/>
<div id="ment_10_div">
**<form action="/ments/vote_up" id="vote_up" method="post">**
<div style="margin:0;padding:0;display:inline">
<input name="authenticity_token" type="hidden"
value="w873BgYHLxQmadUalzMRUC+1ql4AtP3U7f78dT8x9ho=" />
</div>
<input id="Comment_place_id" name="Comment[post_id]" type="hidden" value="3" />
<input id="Comment_id" name="Comment[id]" type="hidden" value="10" />
<input id="Comment_user_id" name="Comment[user_id]" type="hidden" value="2" />
<input name="mit" type="submit" value="Vote up" />
</form>
<label id="ment_10">10</label>
**<form action="/ments/vote_down" id="vote_down" method="post">**
<div style="margin:0;padding:0;display:inline">
<input name="authenticity_token" type="hidden"
value="w873BgYHLxQmadUalzMRUC+1ql4AtP3U7f78dT8x9ho=" />
</div>
<input id="Comment_place_id" name="Comment[place_id]" type="hidden" value="3" />
<input id="Comment_id" name="Comment[id]" type="hidden" value="10" />
<input id="Comment_user_id" name="Comment[user_id]" type="hidden" value="2" />
<input name="mit" type="submit" value="Vote Down" />
</form>
</div>
Can you please help me to solve this Thanks
Share Improve this question asked Jun 3, 2010 at 20:38 felixfelix 11.6k13 gold badges70 silver badges95 bronze badges 2- 11 Using the same ID twice in the same document is not valid HTML. Fix your HTML. – Matti Virkkunen Commented Jun 3, 2010 at 20:41
-
3
You could use the same
class
for the elements with same behavior instead of sameID
. As already mentioned,ID
s are supposed to be unique :] – Ju Nogueira Commented Jun 3, 2010 at 21:25
2 Answers
Reset to default 4Yes, as Matti mentioned above, by the W3C standards ID has to be unique. A nice workaround would be to postfix ment's db ID, e.g. <input id="Comment_39127438"...
Expanding upon what's already been said, the way you should implement this is:
<div id="ment_10" class="ment">
</div>
Then you can select all ments with:
$('.ment')
or a single ment with:
$('#ment_10")
本文标签: javascriptDOM Elements with same id and jQueryStack Overflow
版权声明:本文标题:javascript - DOM Elements with same id and jQuery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742127284a2421998.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论