All Questions

313
votes
6answers
76259 views

Why does jQuery or a DOM method such as getElementById not find the element?

What are the possible reasons for document.getElementById, $("#id") or any other DOM method / jQuery selector not finding the elements? Example problems include: jQuery silently failing to bind an e...
1917
votes
16answers
467693 views

.prop() vs .attr()

So jQuery 1.6 has the new function prop(). $(selector).click(function(){ //instead of: this.getAttribute('style'); //do i use: $(this).prop('style'); //or: $(this).attr('style...
2083
votes
29answers
1937330 views

Change an element's class with JavaScript

How can I change a class of an HTML element in response to an onClick event using JavaScript?
273
votes
4answers
27739 views

Do DOM tree elements with ids become global variables?

Working on an idea for a simple HTMLElement wrapper I stumbled upon the following for Internet Explorer and Chrome: For a given HTMLElement with ID in the DOM tree, it is possible to retrieve th...
629
votes
14answers
157648 views

Why is setTimeout(fn, 0) sometimes useful?

I've recently run into a rather nasty bug, wherein the code was loading a <select> dynamically via JavaScript. This dynamically loaded <select> had a pre-selected value. In IE6, we alrea...
681
votes
23answers
327254 views

How to tell if a DOM element is visible in the current viewport?

Is there an efficient way to tell if a DOM element (in an HTML document) is currently visible (appears in the viewport)? (The question regards Firefox)
151
votes
14answers
138308 views

Can scripts be inserted with innerHTML?

I tried to load some scripts into a page using innerHTML on a <div>. It appears that the script loads into the DOM, but it is never executed (at least in Firefox and Chrome). Is there a way to h...
344
votes
11answers
141273 views

How do I select text nodes with jQuery?

I would like to get all descendant text nodes of an element, as a jQuery collection. What is the best way to do that?
101
votes
9answers
81128 views

Grabbing the href attribute of an A element

Trying to find the links on a page. my regex is: /<a\s[^>]*href=(\"\'??)([^\"\' >]*?)[^>]*>(.*)<\/a>/ but seems to fail at <a title="this" href="that">what?</a> ...
3645
votes
56answers
3341234 views

How to check whether a checkbox is checked in jQuery?

I need to check the checked property of a checkbox and perform an action based on the checked property using jQuery. For example, if the age checkbox is checked, then I need to show a textbox to ente...

Previous Next