activar un clic al cargar la aplicación

I need to trigger a click on "Home" button on loading the app. Home should become red and it should show the corresponding paragraph in rectangle.

$(document).ready(function(){
$('.showSingle').click(function () {
    $('.targetPara').hide();
    $('#p' + $(this).attr('target')).show();
    $('.showSingle').removeClass('selected')
    $(this).addClass('selected');           
});    
});

var active_link = 1; // Change this value to set the active link
$('td[target='+active_link+']').trigger('click');

I an using the abobe jquery code. Pls help me to figure out what is the prob

preguntado el 28 de agosto de 12 a las 11:08

Is this the actual code? If so, you aren't triggering the event on document ready, so nothing will happen because the relevant td aún no existe. -

2 Respuestas

Tu llamada a trigger necesita estar adentro document.ready. You're accessing the DOM, so you have to wait for the browser to parse it. Also, make sure you set up the click event handler before you try to trigger the click. ¡Espero que esto ayude!

Respondido 28 ago 12, 11:08

Maybe the below selector doesn't have "showSingle" css class on it?

$('td[target='+active_link+']')

And what Abraham said (:

Respondido 28 ago 12, 11:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.