Is it legal to create your own CSS attributes?

I am working on a window application for my website. Right now, I have every single window configured as a body of a body. I am adding new windows, literally adding the appropriate code to the end of the body element and deleting them, removing this div. (I am using jQuery for the underlying JavaScript architecture.)

I found that for each window I want to save some values ​​that are not used directly. Let's say I maximize the window, I would like to preserve its previous position and size, so that when I do not maximize it, it will return to its previous position, and not just to a random one. So my real question is whether it will be legal to create custom CSS attributes (knowing that the browser will ignore them) for the sole purpose of storing such information based on div-divs? Or will it be illegal and should I look at another alternative?

Of course, I am familiar with the methods of storing all of this in an array so that the system can work with it blindly, but it is so cute and prone to errors and things, and it would still be a little difficult to work with.

thanks

+4
source share
2 answers

jQuery has a little-known function for this data . With it, you can do this:

 $('#mydiv').data('position', {x: 150, y: 300}); // later var position = $('#mydiv').data('position'); 

If you do not like it (although I find it quite convenient), it is certainly not the case to have custom attributes, although this will make it invalid.

+7
source

I would use the jQuery data() method to store temporary data.

 $('div#window').data('position', { x: 100, y: 200, width: 50, height: 50}); $('div#window').data('state', 'minimized'); 

References

You can also make this data permanent by storing it in cookies or in a server-side session and restoring it on the client when the page loads. Thus, the position and state of the window will be saved even if the user reloads the page.

+8
source

All Articles