If div has no content hide other div

I have the following JS: if ( $(“#secretContent”).children().length == 0) { $(“#seemore”).hide(); }‚Äč and here is a jsFiddle demonstrating my questions. I have the intention of hiding the div with id “seemore” when the div with id “secretContent” has no children/contents. Any help would be much appreciated. Thanks in advance!

rails 3 javascript fine coffeescript referenceerror (class) is not defined

Someone on the RubyRogues podcast once said “Learn CoffeeScript because CoffeeScript writes better javascript than you do.” Sorry, can’t remember who said it… So, I took a very simple WORKING javascript function: togglingii.js function pdtogglejs(id) { $(‘div .partybackground’).removeClass(“hidden”); } Which is being called by this line: <a href=”#” class=”dctoggle” onclick=”pdtogglejs(‘partybackground’)”>Read More…</a> Then I converted it […]

Javascript Alert message runtime error Object Expected

Ok .. this is a strange one as I have NOT seen this before. I have an application that is strictly a Service … no browser involved … and all I want to do is use alert(); for debugging. The only problem is that it causes an Object Expected error even if it is a […]

Order of the associative array in javascript by key and access by index

I have an associative array like: var arr={}; arr[‘alz’]=’15a’; arr[‘aly’]=’16b’; arr[‘alx’]=’17a’; arr[‘alw’]=’09c’; I need to find the previous and next key of any selected element. Say, for key ‘aly’ it will be ‘alz’ and ‘alx’. If possible, I want to access the array by index rather than the key. Currently, I am doing this using […]

Advantage of using prototype over creating functions in the constructor?

Here’s a constructor for an animal object. function Animal(name, sound) { this.name = name; this.sound = sound; this.makeSound = function() { alert(sound); } } I have found that a developer can instead add an instance method to the Animal class via Animal.prototype.makeSound = function() { alert(this.sound); }; and exclude the makeSound method from the constructor. […]

mongoose .find() method returns object with unwanted properties

so, I’ve been working with mongoose for some time and I found some really weird stuff going on. It would be great if someone could enlighten me. The thing is, when using the .find() method of mongoose, the object I get as response is full of properties I don’t know where It came from (I’m […]

Can I remove all ID naming with same character in javascript?

For instance , there is a img id = img_1 , img_2 , img_3 , img_4 and so on.. However, I don’t know the exact number of divs $(‘#img_’).remove seems not working So , How to remove all the img that has an id “img_”? Thanks.

Multiple queries in a loop Parse Cloud Code

I’m having a hard time trying to understand promises, I’m sure I need to use them for this but I don’t know how and other answers don’t help me at all. I’d like to loop over an array, query all the results for each value of the array, then after calculating the average value for […]

how to optimize code in javascript

I think the code(below) is optimized (just use less variables than my initial version of the same logic). How do I really know if its properly optimized ? What factors should I consider during optimization ? Here is the code ( also on jsfiddle ) function process(arr){ var processed = []; for(var i=0,len=arr.length;i<len;i++){ if(processed.indexOf(arr[i]) < […]

How to nest OR statements in JavaScript?

Currently I am creating a filemanager. What I want is to check if the user has selected a video file. The file can be mov, f4v, flv, mp4 and swf. I want to check if my var ext is one of these. What I have is: if(ext == (‘mov’ || ‘f4v’ || ‘flv’ || ‘mp4’ […]