Skip to content
Advertisement

How can I guarantee that my enums definition doesn’t change in JavaScript?

Would the following make the objects fulfil all characteristics that enums have in JavaScript? Something like: Or is there some other way I can do this? Answer Since 1.8.5 it’s possible to seal and freeze the object, so define the above as: or and voila! JS enums. However, this doesn’t prevent you from assigning an undesired value to a variable,

Remove blank attributes from an Object in Javascript

How do I remove all attributes which are undefined or null in a JavaScript object? (Question is similar to this one for Arrays) Answer You can loop through the object: If you’re concerned about this property removal not running up object’s proptype chain, you can also: A few notes on null vs undefined:

Javascript to sort contents of select element

is there a quick way to sort the items of a select element? Or I have to resort to writing javascript? Please any ideas. Answer This will do the trick. Just pass it your select element a la: document.getElementById(‘lstALL’) when you need your list sorted.

jQuery hover and class selector

I wan’t to change the background color of a div dynamicly using the following HTML, CSS and javascript. HTML: CSS: Javascript: EDIT: I forgot to say that I had reasons not to want to use the css way. And I indeed forgot to check if the DOM was loaded. Answer Your code looks fine to me. Make sure the DOM

Scroll to bottom of div?

I am creating a chat using Ajax requests and I’m trying to get messages div to scroll to the bottom without much luck. I am wrapping everything in this div: Is there a way to keep it scrolled to the bottom by default using JS? Is there a way to keep it scrolled to the bottom after an ajax request?

Changing website favicon dynamically

I have a web application that’s branded according to the user that’s currently logged in. I’d like to change the favicon of the page to be the logo of the private label, but I’m unable to find any code or any examples of how to do this. Has anybody successfully done this before? I’m picturing having a dozen icons in

jQuery $(document).ready and UpdatePanels?

I’m using jQuery to wire up some mouseover effects on elements that are inside an UpdatePanel. The events are bound in $(document).ready . For example: Of course, this works fine the first time the page is loaded, but when the UpdatePanel does a partial page update, it’s not run and the mouseover effects don’t work any more inside the UpdatePanel.

Invoking JavaScript code in an iframe from the parent page

Basically, I have an iframe embedded in a page and the iframe has some JavaScript routines I need to invoke from the parent page. Now the opposite is quite simple as you only need to call parent.functionName(), but unfortunately, I need exactly the opposite of that. Please note that my problem is not changing the source URL of the iframe,

Advertisement