-1

I have the following code

<div id="faqEntries">
    <p:inputText disabled="true" class="telDialogField"></p:inputText>
    <br/>
    <p:inputTextarea disabled="true" class="telDialogField"></p:inputTextarea>
    <br/>
    <p:button value="In Ticket übernehmen" class=" telDialogButton"></p:button>
</div>

this part is for showing faq entries from a database. This part is nested inside of a ui:repeat.

what I want to do now is get the surrounding Div when I click the button, so that I can get the Textarea afterwards and copy this text to an other TextArea. Normaly I would just try to do this using id Tags but this does not seem to work with the ui:repeat.

I know how I can copy the content into another textarea but not how to get the first textarea.

FreeKill
  • 13
  • 4
  • Possible duplicate of [How to select JSF components using jQuery?](https://stackoverflow.com/questions/7927716/how-to-select-jsf-components-using-jquery) – Kukeltje Apr 26 '18 at 17:16

2 Answers2

0

There are two ways.

Pure Javascript:

var pDoc = document.getElementById("yourDiv");
var parentDiv = pDoc.parentNode;

Using Jquery:

var parentDiv = $("#yourDiv").parent()
minijavi19
  • 48
  • 2
  • 8
  • From the post: _"Normaly I would just try to do this using id Tags but this does not seem to work with the ui:repeat."_. So using an ID like you do does not work according to the poster – Kukeltje Apr 26 '18 at 16:57
0

You can get the parent element by using .parentElement property.

<div id="faqEntries">
    <p:inputText disabled="true" class="telDialogField"> 
    </p:inputText>
    <br/>
    <p:inputTextarea disabled="true" class="telDialogField"> 
    </p:inputTextarea>
    <br/>
    <p:button onclick="foo(this.parentElement);" value="In Ticket übernehmen" class=" telDialogButton"> 
    </p:button>
</div>

The foo() function can then do whatever you wish with the parent element.

function foo(parent){
    alert(parent.nodeName);
}
Davis
  • 85
  • 2
  • 8