javascript - How to find a div element inside the row table and return the value? -
I have a table under which the foreach statement is being blocked by. Inside the table, you can see that there are various div elements. I want to get and return the value of a div element with class = "divrep" by clicking on the button with class = "postrep" . I tried to do something below but it gives empty objects so I'm not sure if I get the right div element. jQuery: HTML: Try using
$ (Function () {$ ('. Postrep'). Click (function () {var findiv = $ (This) .closest ('div' ['div' [class = "divrep"] '); Findiv.toString ());});});
& lt; Table id = "mytable" & gt; & Lt; Tr & gt; & Lt; Td class = "tdstyle" & gt; & Lt; Div style = "font-weight: bold;" & Gt; @html Displayer (model istam => item.name) & lt; / Div & gt; & Lt; P & gt; @html DisplayFor (Model Itam => Item Dotement) & lt; / P & gt; & Lt; P & gt; & Lt; Input type = "button" id = "like" name = "like" value = "like" style = "color: blue; border: 0px; background color: heir; cursor: indicator" /> & Lt; Input type = "button" class = "reply" name = "reply" value = "reprocessor (s)" /> gt; & Lt; / P & gt; & Lt; Div id = "divrepeply" class = "divrep" & gt; I want to return this string value ... & lt; Div & gt; & Lt; Div class = "editor-area" style = "display: none; margin-down: 5px; margin-top: 5px" & gt; & Lt; Input type = "text" id = "comidvalue" name = "id" class = "id" value = "@ html.DisplayFor (modelItem => item.Id)" /> & Lt; / Div & gt; & Lt; Br / & gt; & Lt; Input type = "text" id = "namerep" name = "name" class = "name" style = "width: 445 pixels; size change: none" /> & Lt; Br / & gt; & Lt; Textarea id = "answer" name = "answer" class = "answer" style = "width: 445 pixels; height: 100px; size: none" & gt; & Lt; / Textarea & gt; & Lt; Br / & gt; & Lt; Input type = "button" class = "postrep" value = "post reply" name = "butname" style = "cursor: pointer" /> & Lt; / Div & gt; & Lt; Br / & gt; & Lt; / Div & gt; & Lt; / TD & gt; & Lt; / TR & gt; & Lt; / Table & gt;
.contents () To capture the text nodes as well as get the element before the hair element and returned collection
$ ('. Postrep'). Click (function () {var findiv = $ (this) closest ('. Divrep'); warning (findiv.contents () [0] .nodeValue);}); Using
.text () , the object will be recommended by
finddiv , but if you think that you have
the searcher like this solution.
Comments
Post a Comment