Both the jQuery and Prototpye JavaScript libraries refuse to allow me to use a variable to select an list item element by index number although they accept a hard coded number.
For example, in Prototype this works:
$$('li')[5].addClassName('active');
But this will not work no matter how I try to cast the variable as a number or inte...
A .container can contain many .components, and .components themselves can contain .containers (which in turn can contain .components etc. etc.)
Given code like this:
$(".container .component").each(function()
{
$(".container", this).css('border', '1px solid #f00');
});
What do I need to add to the line within the braces to select...
I'm looking for any way that I can improve the selector performance of a jQuery call. Specifically things like this:
Is $("div.myclass") faster than $(".myclass")
I would think it might be, but I don't know if jQuery is smart enough to limit the search by tag name first, etc. Anyone have any ideas for how to formulate a jQuery select...
CSS Attribute selectors allow the selection of elements based on attribute values. Unfortunately, I've not used them in years (mainly because they're not supported by all modern browsers). However, I remember distinctly that I was able to use them to adorn all external links with an icon, by using a code similar to the following:
a[href...
Say I have a list as follows:
item1
item2
item3
Is there a CSS selector that will allow me to directly select the last item of a list? In this case item 3.
Cheers!
...
I can't seem to figure out a good way to do this, but it seems like it should be simple. I have an element that I want to append a div to. Then I have another element that I want to clone and shove into that intermediate div. Here's what I was hoping to do:
$("#somediv > ul").after("<div id='xxx'></div>").append($("#someotherdiv").cl...
A few of the third-party applications we use are written in Prototype, and I'm really having trouble with selectors and events. I know how to accomplish it all in jQuery quickly, but I'm not about to load both libraries. Can you provide a few links that do a top-down comparison of selectors and/or events for jQuery and Prototype, so I ca...
I need to figure out what div is visible out of four possible divs using jQuery. Only one of those div's will be visible at any given time.
This is what I have that works so far:
$("#FeatureImage1:visible, #FeatureImage2:visible, #FeatureImage3:visible, #FeatureImage4:visible").attr("id");
Is there a way to refactor this? Is there ...
Is there a case insensitive version of the :contains jQuery selector or should I do the work manually by looping over all elements and comparing their .text() to my string?
...
I am after documentation on using wildcard or regular expressions (not sure on the exact terminology) with the jquery selector.
I have looked for this myself but have been unable to find information on the syntax and how to use it. Does anyone know where the documentation for the syntax is?
EDIT: The attribute filters allow you to sele...
I am creating a tool that will check dynamically generated XHTML and validate it against expected contents.
I need to confirm the structure is correct and that specific attributes exist/match. There may be other attributes which I'm not interested in, so a direct string comparison is not suitable.
One way of validating this is with XPa...
I have some HTML that looks like this:
<ul class="faq">
<li class="open">
<a class="question" href="">This is my question?</a>
<p>Of course you can, it will be awesome. </p>
</li>
</ul>
Using CSS I'm setting the 'p' tag to display:none;. I want to use jQuery to display or hide the 'p' tag when the anchor is cli...
Hi,
I have the following HTML node structure:
<div id="foo">
<div id="bar"></div>
<div id="baz">
<div id="biz">
</div>
<span><span>
</div>
How do I count the number of immediate children of "foo", that are of type "div". In the example above, the result should be two ("bar" and "baz").
Cheers,
Don
...
I am using jQuery to try and trigger a method when a ASP.Net (2.0) dropdown list's change event is handled by jQuery. The problem is that the drop down list is located inside a gridview and even then only when a user has decided to edit a row within that gridview.
I think I have it picking up the object using a ASP code block but the p...
In Mootools, I'd just run if ($('target')) { ... }. Does if ($('#target')) { ... } in jQuery work the same way?
...
Maybe it's the really late night I had but I can't figure this one out. First the html:
<div>
<a href="#internal">Internal Link</a>
<a href="http://external.com">External Link</a>
<a href="#internal2">Internal Link2</a>
</div>
in order to do something on the page instead of going to the link I need to filter it based on if it conta...
I'm wondering why styling an element within a specific class, like this:
.reddish H1 { color: red }
is shown as an example of correct syntax in the CSS1 specification under Contextual selectors:
Cascading Style Sheets, level 1
but it's not shown as an example in the CSS2 spec:
Cascading Style Sheets, Level 2
At least I can't find ...
In jQuery, how do you select the <a> which href is pointing to the current URL
For example:
URL = http://server/dir/script.aspx?id=1
I want to select this <a>
<a href="/dir/script.aspx">...</a>
I tried this but it doesn't work:
var url = window.location.href;
$('#ulTopMenu a["'+url+'"*=href]').addClass("selected");
Probably wrong s...
I have an object, and I want to list all the selectors to which it responds. It feels like this should be perfectly possible, but I'm having trouble finding the APIs.
...
Thanks for reading this
I thought I could use find(), but couldn't make it work. I know I can add IDs or classnames, but would like to know how with the current markup.
Thanks
Here is the HTML
<input name="keywordCheckbox" type="checkbox" value="S" />
<input name="keywordCheckbox" type="checkbox" value="C" />
<input name="keywordChec...