Is there a way to use javascript (jquery) to make the element behave ** exactly ** as if it were clicked (unique situation)

I want the element ' select' to behave as if it were pressed when I click on a completely different separator. Is it possible to make him act as if he was pressed when he is not?

here is my code http://jsfiddle.net/fiddlerOnDaRoof/B4JUK/

$(document).ready(function () {
    $("#arrow").click(function () {
        $("#selectCar").click() // I also tried trigger("click");
    });
});

Until now, he has not worked with .click(); any help..trigger("click");

Update:

From what I now understand, the answer is no, you cannot. Although clicking duplicates functionality, it will not work for specific examples like this. If anyone knows why this is, please write the answer below and I will accept it as the best answer. Preferably, please provide examples for which it will not work correctly.

+3
source share
6 answers

You can use the trigger (event) function, for example ("selector").trigger("click")

+9
source

You can call a function clickwith no arguments that causes an artificial click. For instance:.

$("selector for the element").click();

jQuery ( ) DOM0. , , addEventListener/attachEvent DOM2, : |

jQuery(function($) {

  $("#target").click(function() {
    display("<code>click</code> received by jQuery handler");
  });
  document.getElementById("target").onclick = function() {
    display("<code>click</code> received by DOM0 handler");
  };
  document.getElementById("target").addEventListener(
    'click', 
    function() {
      display("<code>click</code> received by DOM2 handler");
    },
    false
  );

  display("Triggering click");
  $("#target").click();

  function display(msg) {
    $("<p>").html(msg).appendTo(document.body);
  }
});

(), onclick="..." DOM0; .

, , , ; (), , .


, , ; , , , , . , , .

+2

.

$('#yourElementID').click();
+1

jquery, .trigger();

$( '# my_element') ('click').

0

, -, :

$('#elementID').trigger('click');

: http://api.jquery.com/trigger/

0

jsfiddle, .

You chose MooTools, not jQuery. (updated here )

Now, when the click event is fired, there’s not much to choose from. I think you want the second choice to unfold at the same time as the first.

As far as I know, this is not possible.

If not, try the edit event when selected.

0
source

All Articles