DOM elements with identical identifiers and jQuery

Hi, I have several elements with the same structure in my application. The second div element identifier changes according to the comment identifier in db, which is unique. There are elements with id 'vote_up' and 'vote_down'. This is repeated for each comment. What happens is that, as I mentioned, there are a few comments. I want to execute an Ajax request. At first, ajax functions correctly from this structure, but the rest is an HTTP request. Btw I am developing a rails application and I am using jQuery.

<div id="post_comment">
john<i> says </i> Comment<br/>

<div id="comment_10_div">
**<form action="/comments/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="commit" type="submit" value="Vote up" />
</form>

<label id="comment_10">10</label>

**<form action="/comments/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="commit" type="submit" value="Vote Down" />
</form>
</div>      

Could you help me solve this problem? Thanks

+3
2

, , W3C . postfix comment db ID, . <input id="Comment_39127438"...

+4

, :

<div id="comment_10" class="comment">
</div>

:

$('.comment')

:

$('#comment_10")
+4

Source: https://habr.com/ru/post/1748416/


All Articles