Simulating click event on input - JavaScript

后端 未结 3 736
温柔的废话
温柔的废话 2021-01-21 01:42

I\'m trying to simulate a click on an input tag, through the click on an anchor tag, this way I can hide the input and wrap an image inside the anchor tag.

3条回答
  •  悲&欢浪女
    2021-01-21 02:30

    document.getElementById('user_avatar').click() will work

    let fake = document.querySelector('.fake');
    fake.addEventListener('click', function(e) {
      e.preventDefault();
      document.getElementById('user_avatar').click()
    })
    #user_avatar {
      display: none;
    }
    
    
      
    

提交回复
热议问题