Skip to content

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 undef…

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&#821…

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…