5 Replies - 2874 Views - Last Post: 23 April 2010 - 08:17 AM

#1 ptamzz  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 103
  • Joined: 04-March 09

can i use javascript to rewrite the css properties of an html element

Posted 21 April 2010 - 11:30 AM

I've this piece of code with me. Now, what I can make out of it is, it sets the css properties of an html element whose id is popupContact. (If i'm wrong, kindly elaborate)

function centerPopup(){
	$("#popupContact").css({
		"position": "absolute",
		"margin" : "0 auto"
	});
}


I've a css file in which I've already described the properties of the same element having id as popupContact.

What I want to know is that, when this piece of script is executed, what actually happens to the properties of the particular html element?? Can I use javascript to rewrite the actual CSS properties??

Is This A Good Question/Topic? 0
  • +

Replies To: can i use javascript to rewrite the css properties of an html element

#2 oomlaut  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 27
  • Joined: 07-April 09

Re: can i use javascript to rewrite the css properties of an html element

Posted 21 April 2010 - 12:16 PM

Assuming the $ is an alias for jQuery, check out the .css() method. If it is an alias for another library you should refer to its corresponding documentation.

Read the API for a full (and better) description, but essentially the method defines inline styles on the specified element, or set of elements.

Learn jQuery here.

You can also directly manipulate the styling of an element with DOM scripting.
Was This Post Helpful? 1
  • +
  • -

#3 ptamzz  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 103
  • Joined: 04-March 09

Re: can i use javascript to rewrite the css properties of an html element

Posted 21 April 2010 - 01:52 PM

yes, it is jquery. Thanks for helping me out. :)

I think, the .css() method sets the css properties temporarily. What I actually want is a change to the properties of the element permanently so that when we visit the site again, the changes made are still there. Can you please tell me how can I achieved that, or give me anything that might be helpful doing that.
Was This Post Helpful? 0
  • +
  • -

#4 oomlaut  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 27
  • Joined: 07-April 09

Re: can i use javascript to rewrite the css properties of an html element

Posted 22 April 2010 - 06:25 AM

If you want to make a permanent and consistent change to the style, you should declare a style rule, either in the css document, link to a different css file, create a STYLE element in the head, or as in inline style on the element itself.
Was This Post Helpful? 0
  • +
  • -

#5 ptamzz  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 103
  • Joined: 04-March 09

Re: can i use javascript to rewrite the css properties of an html element

Posted 22 April 2010 - 07:13 AM

Ok. Let me explain What i really wanna achieve.

I've a drag & drop box in which i have got two dragable divs. When i drag the div at the bottom to the top, the top one slides down. Now i Want to save that position so that when i visit the page next time, the divs are in their new position i've changed (the bottom one would now be on top while the top one will slide down to the bottom).

What i was thinking was to detect the new position and rewrite the CSS properties for that particular element.

Can you kindly suggest any method to do that??

Thanks :)
Was This Post Helpful? 0
  • +
  • -

#6 oomlaut  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 27
  • Joined: 07-April 09

Re: can i use javascript to rewrite the css properties of an html element

Posted 23 April 2010 - 08:17 AM

If the user has to log in to the site, you could store that positioning in a user-relative database table (position save function called via ajax perhaps?)

Otherwise your best bet is to use a cookie that stores the position information and is recalled/reset on load. Learn about cookies (js)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1