0

I have a div whose content is rendered during runtime (rendered attribute is set false), after a click on a button.

What I'm trying to do is use javascript (with jquery) to manipulate the content of the div. I'm currently working with timeout, but this is unsuitable due to fluctuating loading times.

Is there any way to make javascript notice and execute the function as soon as rendered is set true?

EDIT: I think I expressed myself inexpertly:

What I'm doing concretely: I have a button which executes a sql query and displays the results in a table which is surrounded by a div. The div, thus the table, are set as rendered="false" and are rerendered by clicking the button.

The javascript function that I'm trying to invoke is used to style rows of the table. So the js function needs to check for the div, which is not possible before the div is rendered.

Beejay
  • 183
  • 1
  • 3
  • 13
  • http://stackoverflow.com/questions/11245896/a-way-to-easily-check-if-an-element-was-rendered-in-jsf2 – Deepak Ingole Mar 07 '14 at 11:14
  • @Pilot Sorry Pilot, that's not what I'm looking for, since I need javascript to check for the element being rendered, not jsf – Beejay Mar 07 '14 at 11:25
  • 1
    why don't you use, `oncomplete` on that button to call that javascript styling function... if it is primefaces of course ! – Hatem Alimam Mar 07 '14 at 11:50
  • @HatemAlimam: That mate, works perfectly. Thank you very much! Submit this as an answer, I will approve! – Beejay Mar 07 '14 at 12:02

2 Answers2

1

Use oncomplete on that button to call that javascript styling function.

<p:commandLink oncomplete="jsFunction()" >

Hope this helps.

Hatem Alimam
  • 9,968
  • 4
  • 44
  • 56
0

You can bind the DOMNodeInserted event, as described here. That enables you to do something like this:

$(document).bind('DOMNodeInserted', function(event) {
    var element = $(event.target);
    if (element.hasClass("myDiv")) {
        $(element).text("changed Content");
    }
});
doque
  • 2,723
  • 6
  • 27
  • 44