javascript - Manually trigger click event on other DOM element in knockout viewmodel page -


in html:

<input type="image" src="http://placehold.it/145x145" data-bind="click: imgclick"/> <input type="file" id="artimage" style="display: none;" /> 

in viewmodel:

var imgclick = function () {     $("artimage").click(); }; 

if put debug breakpoint on '$("artimage").click()' line, hit. no error in console, nothing happens on screen though.

seems work ok in fiddle? http://jsfiddle.net/nvrsp/ i'm not sure why it's not working on page.

(in case asks, i'm trying clickable image trigger file upload browse)

your selector probally returning nothing have not given # "this id."

try

$("#artimage").trigger('click'); 

see link list of valid selectors: https://cdn.tutsplus.com/net/uploads/legacy/154_cheatsheet/jquery12_colorcharge.png


Comments