Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4610100
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:05:00+00:00 2026-05-22T01:05:00+00:00

<div rownumber=0 messageid=29 style=margin:1px 1px 1px 1px; border:1px solid black> <input type=button value=Vote id=vote>

  • 0
<div rownumber="0" messageid="29" style="margin:1px 1px 1px 1px; border:1px solid black">
    <input type="button" value="Vote" id="vote">
    <input type="button" value="Flag" id="flag">
</div>

These <div> elements are added dynamically to my page. How do I bind a Jquery click event to each of these vote and flag buttons and get the rownumber or messageId value from whatever parent <div> the button is in.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:05:01+00:00Added an answer on May 22, 2026 at 1:05 am

    First of all, don’t use id for those buttons if you’re going to have more than one. An HTML ID means that you can uniquely identify the element by that name, which you can’t if there’s two or more. Instead, make vote and flag classes.

    Next, do this:

    $('.vote').live('click', function() {
        var parent = $(this).parent();
        vote(parent.attr('rownumber'), parent.attr('messageid'));
    });
    

    I’m assuming you have a JavaScript function called vote. The important thing is what’s passed to it: that will get the parent of the element that has been clicked on and then get its rownumber attribute. Using live will ensure that any elements you create after you call it will also have the event bound to it.

    As an aside, you should probably use data-row-number and data-message-id or something similar for the attributes. HTML doesn’t recommend making up your own attributes randomly: if you prefix them with data-, they’re guaranteed not to clash with anything. You can then retrieve the information using either attr as above or jQuery’s data function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<div rownumber=0 messageid=112 class=post style=position: relative; top: 0px;> <div class=post_body>hey hey hey</div> <div class=post_info
<div rownumber=0 messageid=141 class=post style=position: relative; top: 0px;> <div class=post_body>testbox</div> <div class=post_info style=top: 0px;>
<div id=container> <div rownumber=0 messageid=155 class=post style=position: relative; top: 0px;> <div class=post_body><span>asdfjhasf as dfkhgfk
$(div).append($(document.createElement(input)).attr({ 'id': 'post_category', 'value': 'item', 'type': 'checkbox','checked': true })); I am trying to create
div.horizontalRule { clear:both; width:100%; background-color:#d1d1d1; height:1px; margin-top:5px; margin-bottom:5px; } This is what I am
div#thing { position: absolute; top: 0px; z-index: 2; margin: 0 auto; } <div id=thing>
div { margin:90px auto; } This code centers the div in chrome with a
My div is closing itself. <html><head><title></title> <script type=text/javascript charset=utf-8 src=jquery-1.7.min.js></script> <script> $(document).ready(function(){ $(#wrapper).append( '<div
%div{:class => [@item.type, @item == @sortcol && [:sort, @sortdir]] } Contents could render as
Div 'canvasesdiv' element contains three HTML5 canvases. <div style=position: relative; width: 400px; height: 300px;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.