javascript - How to find a div element inside the row table and return the value? -
i have table below row beingness looped foreach statement. within table, there various div elements can see. want , homecoming value of 1 of div element class="divrep" clicking button class ="postrep". tried below returns null object i'm not sure if right div element.
jquery:
$(function () { $('.postrep').click(function () { var findiv = $(this).closest('table').find('div[class="divrep"]'); alert(findiv.tostring()); }); });
html:
<table id="mytable"> <tr > <td class="tdstyle" > <div style="font-weight:bold;"> @html.displayfor(modelitem => item.name) </div> <p > @html.displayfor(modelitem => item.comment) </p> <p> <input type="button" id="like" name="like" value="like" style="color:blue;border:0px;background-color:inherit;cursor:pointer" /> <input type="button" class ="reply" name="reply" value="replie(s)" /></p> <div id="divreply" class ="divrep"> want homecoming string value... <div> <div class="editor-field" style="display:none; margin-bottom:5px;margin-top:5px"> <input type="text" id="comidvalue" name="id" class="id" value="@html.displayfor(modelitem => item.id)" /> </div> <br /> <input type="text" id="namerep" name="name" class="name" style="width:445px;resize:none" /> <br /> <textarea id="reply" name="reply" class="reply" style="width:445px;height:100px;resize:none" ></textarea> <br /> <input type="button" class="postrep" value="post reply" name="butname" style="cursor:pointer" /> </div> <br /> </div> </td> </tr> </table>
try utilize .contents()
grab text nodes kid elements , first element returned collecion,
$('.postrep').click(function () { var findiv = $(this).closest('.divrep'); alert(findiv.contents()[0].nodevalue); });
using .text()
on finddiv
object recommended, if suppose have more text nodes within of finddiv
prefer solution.
javascript jquery html
No comments:
Post a Comment