On 07/08/2007, at 8:12 AM, David Garcia Ortega wrote:
Hi JQueriers,
I have a question for you. Well, my problem is the following:
In .js file and inside $(document).ready, I have the following
code:
$(document).ready(function() {
....
$('#menu').find('a').eq(0).click( function ()
{
$('#content').load('html/senas_identidad.html');
}
);
...
Well, when I click on the first link of the menu div, the hmtl file
"senas_identidad.html" loads correctly inside the content div.
The content of "senas_identidad.html" (stupid content) is:
<h1>Señas de iasdfasdasddfsadfs</h1>
<input type="button" title="Publicar novedades seleccionadas"
value="Publicar" name="Publicar" />
<input type="button" title="Publicar novedades seleccionadas"
value="C" name="Publicar" />
<p> hola </p>
Now, I would like that when the user presses the button which value
is "Publicar", an alert message is shown.
First I tried putting the following code inside $(document).ready:
$(document).ready(function() {
...
$('#content').find('[EMAIL PROTECTED]
[EMAIL PROTECTED]').click( function ()
{
alert('Hola caracola');
}
);
...
But it doesn't work. It doesn´t execute. I think that has sense
because $(document).ready function only executes when the page is
being loaded and it's ready to be manipulated.
Secondly, I tried to put the same code but out of $
(document).ready:
$(document).ready(function() {
....
});
$('#content').find('[EMAIL PROTECTED]
[EMAIL PROTECTED]').click( function ()
{
alert('Hola caracola');
}
I don't know if it is correct but it doesn't work.
Any ideas of how can I associate a click event handler on button which
value is "Publicar"?
Thanks a lot!!!
P.D. : I am a javascript and JQuery newbie, so sorry if it is a stupid
error.
This one of the most common newbie (I mean that in a nice way)
questions there is. You need to put the code for attaching the
handler to the button in a 'callback' function for the load()
function. This just means put the code as the second parameter of the
load function and it will execute it once the load has finished so
that the element you are trying to attach behaviour to exists.
Something like this:
$(document).ready(function() {
....
$('#menu').find('a').eq(0).click( function (){
$('#content').load('html/senas_identidad.html', function() {/*put
your code here*/});
});
...
});
Joel Birch.