+ 2
How to move javascript elements to html or CSS?
Hello everyone! I need your help. I would like to know how it is possible to move certain javascript elements using html or CSS in the browser. I tried a lot of things, but for some reason nothing worked. Thank you so much in advance! Sorry for my English, I'm just from Russia;) 🙃
1 Antwort
+ 2
The wording of this question is just a little confusing but I'm pretty sure you want to move HTML elements using JavaScript. You don't want to move JavaScript elements using html and CSS because JavaScript code isn't something visible in a page.
You can move any element on a page but you need to first set the CSS position to one of: relative, absolute, or fixed. After you use one of those positions, you can move the element by adjusting top, left, bottom, or right.
If you know how to open the JavaScript console, run the following while looking at the "ineedhelp" tag on this question. You should see that HTML element move as soon as the following runs:
var e = document.querySelector('a[data-value="ineedhelp"]');
e.style.position = 'relative';
e.style.left = '10px';
e.style.top = '-10px';
e.style.zIndex = '999';
Since you want to move with JavaScript, also note that same movement can be accomplished with CSS. CSS can also animate movement.