Query event click jquery


I'm learning, I know some php and little jquery. I have to make some adjustments to an application of my work, developed in cake php. At this moment, clicking on a link takes me to a previous screen. I need to give that same behavior to a button that I have below. The original line is:

 <a href="<?php echo $this->Html->url(array('controller' => 'pages', 'action' => 'display', 'preguntas')); ?>" class="reload_link productos">
          << Volver a Categorias

When you click on < < Back to Categories returns a screen. I have done the following:

			'<a href="<?php echo $this->Html->url(array('controller' => 'pages', 'action' => 'display', 'preguntas')); ?>" class="reload_link productos">';

The idea is that you do not perform the default behavior, that you make the call to the page of the first code. Any help on how to do it with jquery to see if I can understand? I failed to add that what I did did not work for me .. Thanks !!

asked by look68 27.12.2016 в 14:50

3 answers


You can save yourself the function click of jquery and do this:

<button onclick="window.location.href='<?php echo $this->Html->url(array('controller' => 'pages', 'action' => 'display', 'preguntas')); ?>'">Redireccion con boton</button>


As you need to be with the jquery event, I leave this option:

    window.location = "<?php echo $this->Html->url(array('controller' => 'pages', 'action' => 'display', 'preguntas')); ?>";
answered by 27.12.2016 в 14:55

You can use the function that they tell you above

window.location.href = "<?php echo $this->Html->url(array('controller' => 'pages', 'action' => 'display', 'preguntas')); ?>"; and place it within your function with a validation of the event you wish to perform. everything depends on what action you take as an execution event.

answered by 27.12.2016 в 21:50

You can also use the preventDefault(); property

$( "a" ).click(function( event ) {
  // aca viene lo que tu quieras


the preventdefault property prevents the event from propagating automatically but will instead do what you place in that function exclusively

answered by 23.06.2017 в 22:11