Vijay Kumar B Vijay Kumar B - 1 year ago 51
HTML Question

trigger click when i click neibour element

Hi I wnat to downloade when input type submit is clicked
Here in my code

<input type="submit" value="Try a sample" class="wpcf7-form-control wpcf7-submit">
<a href="<?php echo get_template_directory_uri()?>/pdf/AttackonNantucket.pdf" class="ddownload-button" download>Ram</a>

Answer Source

You need to do this.

$('input[type="submit"]').on('click', function(){
  $(this).next().get(0).click();
})

Clicking on the submit , trigger an click for the next element which is hyper link in this case.

As you have a class on the href you could do this too.

$('input[type="submit"]').on('click', function(){
  $('.ddownload-button').get(0).click();
})

$('input[type="submit"]').on('click', function() {
  $(this).next().get(0).click();
})

$('a').on('click', function() {
  alert('Ram clicked')
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="submit" value="Try a sample" class="wpcf7-form-control wpcf7-submit">
<a href="<?php echo get_template_directory_uri()?>/pdf/AttackonNantucket.pdf" class="ddownload-button" download>Ram</a>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download