Query event click jquery

1

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
        </a>

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

		$("#btn-volver").click(function(e){
			e.preventdefault();		
			'<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
source

3 answers

2

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>

EDITING

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

$("#btn-volver").click(function(e){
    window.location = "<?php echo $this->Html->url(array('controller' => 'pages', 'action' => 'display', 'preguntas')); ?>";
});
    
answered by 27.12.2016 в 14:55
1

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
0

You can also use the preventDefault(); property

<script>
$( "a" ).click(function( event ) {
  event.preventDefault();
  // aca viene lo que tu quieras

});
</script>

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