How do I collect data from a div to use in a form

2019-07-29 09:23发布

I must first admit that I am not super proficient at jQuery. I am trying to build a messaging system. I have a stream of messages that contain unique information divided into divs with unique identifiers. These divs also contain other information that I wish to pass to a form. In each div is a link that starts a function. That function is to launch an ajax request to get a form.

How do I dynamically generate these links to collect the data from it's parent div and insert it into the form I am requesting? Here is some of the code for the messages:

<div id="4000" class="message messages">
<a name="messagestamp_#"></a>
<table border="0" cellpadding="0" cellspacing="0" class="messagetable">
<tr>
    <td valign="top" width="80" rowspan="3">
        <div class="usr">
            UsrName
        </div>
    </td>
    <td class="message_data" valign="top" width="100%"> 
        <div class="message_header">
            <ul>
                <li class="ticker">...</li>
            </ul>
        </div>
    </td>
</tr>
<tr>
<td valign="top">
        <div class="tweet_content">
            <div class="tweet_text" class="">Some words will flow here. And here is another line. The standard carrige return will now cause a wrap to another line.
            </div>
        </div>  
    </td>
</tr>
<tr>
    <td>
        <div class="message_toolswrapper">  
        <div class="message_timestamp show">
            Aug 13th at 6:34am
        </div>
        <div class="message_tools hide">    
            <span class="message_social">
                <ul>
                    <li>...</li>
                </ul>
            </span>     
            <span class="message_options">
                <a href="#" id="reply_link">reply</a> |
            </span>     
        </div>
        </div>  
    </td>
</tr>
</table>
</div>

The data I wish to collect is the id in the initial div tag as well as the content div tag classed "usr". And the link I wish to use is the href "reply_link.

The link already does a number of things, such as change the visibility of a div and hide all others. I need it to also, pass this information to my form. It is currently using a .load Ajax method.

Any help would be greatly appreciated. Thank you.

标签: forms jquery
1条回答
我欲成王,谁敢阻挡
2楼-- · 2019-07-29 09:32
var linkval = $("#reply_link").attr('href');
var userName = $('.usr').html();
var id = $('.messages').attr('id');
查看更多
登录 后发表回答