Sniffed
Sniffed

Reputation: 1

How to lock JavaScript element on page?

I made an new element in Javascript and appendChilded it to an parentNode of HTML element, everything seems great, I see it and can put data in it, but when I'm trying to change size of my browser, or scroll it this element is "following me".

How can I "lock" it, so it won't move from the place I put it in?

Thank You everyone for answering. I finally made it! :) I used method wrote by @Abhishek Verma.

Upvotes: 0

Views: 1244

Answers (3)

Amit Prajapati
Amit Prajapati

Reputation: 1190

You can create element and apply following css class.

.StaticElement
{
 position: static;
 top: 0:
 left: 250;
}

You can change the position of div by changing the value of top an left element in css.

Upvotes: 2

Abhishek Verma
Abhishek Verma

Reputation: 489

In you css do
.parentDiv { position: fixed; }

Upvotes: 0

Mkl Rjv
Mkl Rjv

Reputation: 6933

In CSS, set the position property value to 'absolute'. This will maintain the position relative to the parent <div> no matter how far you scroll through.

#yourdiv {
    position:absolute;
}

Edit

Just make sure your parent div also has a position property value and it is anything other than 'static', or unset.

For more info on CSS positioning, please refer: http://www.w3schools.com/cssref/pr_class_position.asp

Upvotes: 0

Related Questions