0

I'm new at JQuery and I'm having some issue:

This is the function:

 $(document).ready(function() {
            $("#editButton").click(function() {
                alert('test');

            });
});

and this is the button:

<h:commandButton   id="editButton"/>  

Then the JQuery doesnt work, but if I change the h:commandButton to <button> it does work.

Any idea why this happens?

Thank you!

Lucas
  • 129
  • 9
  • 1
    what us commandButton?? – Ehsan Sajjad May 24 '14 at 21:23
  • @EhsanSajjad It is part of the JSF Framework. Although this should work fine and just for OP's information, the string values are actually referenced as a variable contextually and stored elsewhere to stay aligned with the mvc pattern of JSF. `but if I change the h:commandButton to it does work` Elaborate on this fact. Change it to what? What is the rendered output of the `h:commandButton` in your HTML? Is it not a proper button. – Ohgodwhy May 24 '14 at 21:25
  • 1
    *"but if I change the h:commandButton to it does work"* What change makes it work? I don't understand. Overall your questions no information to debug the problem. [Learn how to](http://www.creativebloq.com/javascript/javascript-debugging-beginners-3122820) [**debug** JavaScript](https://developers.google.com/chrome-developer-tools/docs/javascript-debugging) yourself. – Felix Kling May 24 '14 at 21:26
  • Sorry fellows, fixed the syntax. I pasted some wrong information. – Lucas May 24 '14 at 21:39
  • are there some error in the console?? – user3127896 May 25 '14 at 07:02
  • no, theres no error in the console. – Lucas May 25 '14 at 14:04

1 Answers1

-2
<button id="editButton">Doh!</button>

or

<input type="button" id="editButton" value="Doh!">

I have never seen

<h:commandButton />

and it gives me nothing to click. However

<h:commandButton id="editButton">Doh!</h>

does produce an element that jQuery can find

enter image description here

(the dropshadow is added, actual element is just Doh!) and the alert() works.

gordon
  • 1,152
  • 1
  • 12
  • 18