0

I am converting a jQuery code to vuejs. I have a hard time doing it. I tried to search but I can't find anything clear.

Sample jQuery code is to get the last div top position. The code is like this:

var top = parseInt($(".d1 > .d2> div").last().css("top"));

My template code is :

     <template>
        <div class="div1" >
           <div class="div2" ref="busstop">
              <div v-html="renderEl()"></div>
           </div>

           <button @click='test()'>testing</button>
        </div>
    </template>

Any Idea on how to convert in to vuejs? Any help is much appreciated. Thank you.

3
  • Can you show ur code html ? Commented Jan 4, 2021 at 1:50
  • @QuangPhu Hi. Updated my question and included the html template Commented Jan 4, 2021 at 1:53
  • Does this answer your question? Convert from jQuery to Vue? Commented Jan 4, 2021 at 2:29

2 Answers 2

3

in ur case, i will using ref to get lastChildElement div by using lastElementChild

First, to get the last child element

this.$refs.busstop.lastElementChild

and to style for this element

this.$refs.busstop.lastElementChild.style.fontSize = "30px";

like that

Sign up to request clarification or add additional context in comments.

3 Comments

Damn, never used lastElementChild, good one !
@kissu what about lastChild
neither, usually I use CSS for that purpose.
1

Alright, so if I understand properly, you want to:

  • have a parent w/ a reference
  • select the last element of this specific parent
  • get it's window's position from the top ?

Here is a demo on how to do this in CSS + Vue.
https://codesandbox.io/s/jovial-fog-td190?file=/src/App.vue

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.