class - jQuery select child node (hidden field) within table cell -


i trying refactor code , on class click want access hidden value of div contained inside class. see code below:

<tr>     <td>@html.labelfor(m => m.enquirerdetailspopup, "enquirer details popup")</td>     <td class="btnsettingstoggle" style="text-align: right; padding-left: 10px;">         <div style="float: right;" id="btnenquirerdetailspopup">             @html.hiddenfor(m => m.autoworkflowofenquiry, new { id = "hdnenquirerdetailspopup" })         </div>     </td> </tr>    $('.btnsettingstoggle').click(function () {      // hidden value that's inside click        }); 

i have ten of these table rows want use few lines of javascript hidden field value within class of btnsettingstoggle.

your jquery needs more this:

$(".btnsettingstoggle").on("click", function(){     $hiddenvalue = $(this).find("input[type=hidden]").val();      alert($hiddenvalue); }); 

but better, put function of own, jquery simplified to

 $(".btnsettingstoggle").on("click", gethiddenvalue); 

edit:

so, completeness:

function gethiddenvalue() {     $hiddenvalue = $(this).find("input[type=hidden]").val();     alert($hiddenvalue);   }  $(".btnsettingstoggle").on("click", gethiddenvalue); 

edit:

this solution not use id, quicker, because 10 rows mentioned. i've made assumption id unknown.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -