Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67497

get the index of an element that is inside an id element [duplicate]

$
0
0

This question already has an answer here:

So I am trying to get the index of a focused input inside a parent element when clicking enter inside that input, but it doesn't work. Here is my snippet

new Vue({
el: '#container',
data: {
},
methods: {
  enter(){
  console.log($('[name=' + document.activeElement.name + ']').index())
          }
  }
})
input{display: inline-block;}
span{color: grey;font-size: 10px;display: block;}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script><div id="container"><form method="POST" @keyup.enter.prevent="enter"><input type="text" placeholder="name"><span>expected input 0</span><input type="email" placeholder="email"><span>expected input 1</span><input type="password" placeholder="pass"><span>expected input 2</span></form></div>

Viewing all articles
Browse latest Browse all 67497

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>