mardi 4 août 2015

How to access outer innerHTML of some nested div in javascript function

To keep it simple, I have below html code:

<div class = "customers" data-popover="true" data-html=true
 data-content="
  <table>
      <c:forEach items="${element.first}" var="btnVal" varStatus="loop"> 
        <c:if test="${not loop.first}">
        <tr> <button onclick='setTestname(innerHTML)' class='btn btn-primary'> ${btnVal}</button> </tr>
        <tr>&nbsp</tr>
        </c:if>
      </c:forEach>  
   </table>
  ">
 <br>${element.first.get(0)}
</div>

Here I am trying to use the value of the clicked button using below javascript function:

function setTestname(test){
  test = test.toString().trim();

  document.getElementById('hiddenCostomer').value=test;                     
  setLogfilename(test);
  document.getElementById('form1').submit();
}

Above code works fine, but I am not sure abt how to access value of div as well. I want to pass two values to setTestname

  1. ${btnVal}
  2. ${element.first.get(0)}

How to get value of ${element.first.get(0)}

EDIT : I want the exact value of div on which the button is clicked , not the entire DOM.

Aucun commentaire:

Enregistrer un commentaire