jQuery.fn.nextUntil = function(expr, includes){
var match = [];
includeFirst = includes.first ? true : false;
includeLast = includes.last ? true :
false;
// We need to figure out which elements to push onto
the array
this.each(function(){
// Traverse through the sibling nodes
if (includeFirst)
match.push(this);
for (var i = this.nextSibling; i; i =
i.nextSibling) {
// Make sure that we're only dealing with
elements
if (i.nodeType != 1)
continue;
// Add it on to the stack if include is set
if (includeLast) {
match.push(i);
}
// If we find a match then we need to stop
if (jQuery.filter(expr, [i]).length)
break;
// Add it on to the stack if include is not
set
if (!includeLast) {
match.push(i);
}
}
});
return this.pushStack(match, arguments);
}
$(document).ready(function(){
$('label').each(function(){
$(this).nextUntil('label', {first: true, last:
false}).wrapAll('');
});
});
Name
Age
Expanding on my example below, with the each function.
First final all elements. Then do whatever you want with the element.
$("span[printData]").each( function( key, elementRef){
alert( $(elementRef).text() );
});
On May 4, 2:16 pm, Andy H wrote:
> Here is an actual example. Would anyone know why this isn't working?
> What I find weird is if I do a single line ( alert($("span").attr
> ("printElement")); ) it works fine. But if I try to use the each()
> function following it, nothing happens.
>
> Any help would be great.
>
> Thanks!
>
> HTML:
>
> This is the first span
> 1
> This is the first span 2 span>
> This is the first span 3
> This is the first span 4 span>
> This is the first span 5
> This is the first span 6 span>
> This is the first span 7
> This is the first span 8
> This is the first span 9
>
> Output:
>
>
> Javascript:
>
> $(document).ready(function() {
>
> //alert($("span").attr("printElement"));
>
> $("span").each(function() {
> $(this).attr("printElement").each(function() {
>
> });
> });
>
> }
>
> On May 4, 1:33 pm, Andy H wrote:
>
> > For some reason this post disappeared. Can anyone answer this?
>
> > Thanks!
>
> > On May 1, 10:01 am, Andy wrote:
>
> > > This is an odd questions. I have a huge form with a lot of data.
> > > There is a table that data in it I need to display on a print screen
> > > (of course this data isn't being displayed in the regular table). So,
> > > I put the display text in a span tag.
>
> > > So, this is how each item will look:
>
> > > Item 1
> > > Item 2
>
> > > I need a way to grab all spans on the page that have the attributte of
> > > "printData" and grab that text inside that attribute and print it out.
>
> > > Any thoughts?- Hide quoted text -
>
> > - Show quoted text -
You need to read the jquery selector docs at
http://docs.jquery.com/Selectors/attributeHas#attribute
Below is the code that will get your data.
$("span[printData]").text();
On May 4, 12:33 pm, Andy H wrote:
> For some reason this post disappeared. Can anyone answer this?
>
> Thanks!
>
> On May 1, 10:01 am, Andy wrote:
>
> > This is an odd questions. I have a huge form with a lot of data.
> > There is a table that data in it I need to display on a print screen
> > (of course this data isn't being displayed in the regular table). So,
> > I put the display text in a span tag.
>
> > So, this is how each item will look:
>
> > Item 1
> > Item 2
>
> > I need a way to grab all spans on the page that have the attributte of
> > "printData" and grab that text inside that attribute and print it out.
>
> > Any thoughts?
if you had:
var json = {"4":{"6":"1"},"3":{"1":"1","2":"1"}}
and this div:
then this code:
$.each(json, function(Parent, Values) {
$("#Results").append("Parent: " + Parent + "");
$.each(values, function(key, val) {
$("#Results").append("-- Key: " + key + ", Value: " +
val + "");
});
});
Would result in
Parent: 4
-- Key: 6, Value 1
Parent 3
-- Key: 1, Value 1
-- Key: 2, Value 1
On May 4, 1:56 pm, Dman wrote:
> Hello, I recently learnt jQuery but I am having problems on working
> with JSON. I am loading the JSON data from PHP file using $.getJSON.
> The JSON returned is {"4":{"6":"1"},"3":{"1":"1","2":"1"}} and array
> for reference is
> Array
> (
> [4] => Array
> (
> [6] => 1
> )
>
> [3] => Array
> (
> [1] => 1
> [2] => 1
> )
>
> )
> The problem is that I don't know the JSON values. Is there any way I
> can loop through JSON so I can access "4", its child "6" and value 1?
> Or I will have to make another JSON structure?
On May 1, 10:25 am, bluejohn wrote:
> Hi,
>
> I'm running an A/B test using a 3rd party javascript testing app. I'm
> loading the jquery script with the tool.
>
>
> $(document).ready(function(){
> $(".cartInStock").css({display : " none "});
> });
>
>
> The problem is that the original CSS displays (what I want to hide)
> while the page is loading, but as soon as it finishes the the script
> updates the css and the element disappears.
>
> The script itself loads fairly high up on the page. I'm not sure if
> this is the script or the A/B testing tool causing the delay.
>
> Any suggestions?
It depends on the size of your document. The function you passed to
ready() will be executed only after the whole DOM has loaded, if your
page is long it's likely that you'll have a delay.
See here for a practical alternative (ignore the fancy title):
http://www.learningjquery.com/2008/10/1-awesome-way-to-avoid-the-not-so-excellent-flash-of-amazing-unstyled-content
Here is an actual example. Would anyone know why this isn't working?
What I find weird is if I do a single line (alert($("span").attr
("printElement"));) it works fine. But if I try to use the each()
function following it, nothing happens.
Any help would be great.
Thanks!
HTML:
This is the first span
1
This is the first span 2
This is the first span 3
This is the first span 4
This is the first span 5
This is the first span 6
This is the first span 7
This is the first span 8
This is the first span 9
Output:
Javascript:
$(document).ready(function() {
//alert($("span").attr("printElement"));
$("span").each(function() {
$(this).attr("printElement").each(function() {
});
});
}
On May 4, 1:33 pm, Andy H wrote:
> For some reason this post disappeared. Can anyone answer this?
>
> Thanks!
>
> On May 1, 10:01 am, Andy wrote:
>
>
>
> > This is an odd questions. I have a huge form with a lot of data.
> > There is a table that data in it I need to display on a print screen
> > (of course this data isn't being displayed in the regular table). So,
> > I put the display text in a span tag.
>
> > So, this is how each item will look:
>
> > Item 1
> > Item 2
>
> > I need a way to grab all spans on the page that have the attributte of
> > "printData" and grab that text inside that attribute and print it out.
>
> > Any thoughts?- Hide quoted text -
>
> - Show quoted text -
We'd have to see more of the source code than to diagnose the issue, it's
far beyond that local piece.
-Original Message-
From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On
Behalf Of introvert
Sent: Monday, May 04, 2009 2:55 PM
To: jQuery (English)
Subject: [jQuery] Re: jquery object and functions
I get the same error.
On May 4, 9:51 pm, "Jordon Bedwell" wrote:
> Try:
>
> $(this).find('img').attr({'src':img[n][0],'alt':img[n][1]});
>
> -Original Message-
> From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On
>
> Behalf Of introvert
> Sent: Monday, May 04, 2009 2:38 PM
> To: jQuery (English)
> Subject: [jQuery] jquery object and functions
>
> Hello.
>
> I'm having problems with the following code:
>
> var img = [];
> //
> var o = this.find('img');
> o.attr('src', img[n][0]).attr('alt', img[n][1]);
>
> The error I get is:
> o.attr("src", img[n][0]).attr is not a function
>
> What am I doing wrong?
>
> Many thanks in advance!
I get the same error.
On May 4, 9:51 pm, "Jordon Bedwell" wrote:
> Try:
>
> $(this).find('img').attr({'src':img[n][0],'alt':img[n][1]});
>
> -Original Message-
> From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On
>
> Behalf Of introvert
> Sent: Monday, May 04, 2009 2:38 PM
> To: jQuery (English)
> Subject: [jQuery] jquery object and functions
>
> Hello.
>
> I'm having problems with the following code:
>
> var img = [];
> //
> var o = this.find('img');
> o.attr('src', img[n][0]).attr('alt', img[n][1]);
>
> The error I get is:
> o.attr("src", img[n][0]).attr is not a function
>
> What am I doing wrong?
>
> Many thanks in advance!
Try:
$(this).find('img').attr({'src':img[n][0],'alt':img[n][1]});
-Original Message-
From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On
Behalf Of introvert
Sent: Monday, May 04, 2009 2:38 PM
To: jQuery (English)
Subject: [jQuery] jquery object and functions
Hello.
I'm having problems with the following code:
var img = [];
//
var o = this.find('img');
o.attr('src', img[n][0]).attr('alt', img[n][1]);
The error I get is:
o.attr("src", img[n][0]).attr is not a function
What am I doing wrong?
Many thanks in advance!
thanks so much for the reply!
I was able to apply the class but was unable to figure out how to
remove the existing active class on other links. I'll try this out.
Again, thanks so much!
On May 4, 7:48 am, Nathan wrote:
> If I understand you both correctly.
>
> You'll need to add a class of active to the clicked nav item and
> remove the class active from the nav item the was previously active.
>
> You can do this with:
>
> $(function(){
> $('#nav li a').click(function(){
> $('#nav li a').removeClass('active');
> $(this).addClass('active');
> });
>
> });
>
> $('#nav li a').click - Gets the click.
> $('#nav li a').removeClass('active') - Removes the class active from
> all #nav li a
> $(this).addClass('active') - The 'this' in that statement defines the
> #nav li a that was clicked
>
> On May 3, 12:24 pm, jQnoob wrote:
>
> > I'm also having this problem. I'm using localscroll on a one-page
> > site and need to add an active state to the navigation items. the
> > problem is, it doesn't seem to work with local anchors. Not sure if it
> > matters, but I also have sticky header and footer.
>
> > Here's some example code:
>
> > HTML:
> >
> >
> > logo
> >
> > home
> > about
> > portfolio
> > contact
> > rss > a>Subscribe to our RSS Feed
> >
> >
> >
>
> > JSCRIPT:
> > jQuery(function( $ ){
>
> > // Scroll the x axis
> > $.localScroll.defaults.axis = 'x';
>
> > // Scroll if there's a hash (#something) in the url
> > $.localScroll.hash({
> > target: '#content', // Could be a selector or a jQuery
> > object too.
> > queue:true,
> > duration:1500
> > });
>
> > /**
> > * NOTE: I use $.localScroll instead of $('#navigation').localScroll
> > () so I
> > * also affect the >> and << links. I want every link in the page to
> > scroll.
> > */
> > $.localScroll({
> > target: '#content', // could be a selector or a jQuery
> > obje8¶ct too.
> > queue:true,
> > duration:1000,
> > hash:true,
> > onBefore:function( e, anchor, $target ){
> > // The 'this' is the settings object, can be
> > modified
> > },
> > onAfter:function( anchor, settings ){
> > // The 'this' contains the scrolled element
> > (#content)
> > }
> > });
>
> > $(function(){
> > var path = location.pathname.substring(1);
> > if ( path )
> > $('ul#nav li a...@href$="' + path + '"]').attr('class', 'active');
> > });
That explains my issue very well and will save me a lot of headaches.
(and gives a few ideas for a debug plugin)
thank you
-Olivier
Ricardo wrote:
Could not make much sense out of your video either :D
The thing is: when you log an object or element in firebug, it's just
a reference to the object itself, not a snapshot of it at that instant
in time. It will always show the object as it is *now*. Try this in
the console:
x = {a:1};
console.log(x);
x.a = 2;
You'll see that x.a == 2 in the object inspector, not 1. If you
further change x's properties they will continue to be updated in the
inspector. The printed line will not, it will keep showing "Object
a=1", ignore it.
On May 4, 3:30 pm, Olivier Percebois-Garve
wrote:
Ricardo wrote:
On May 4, 11:33 am, Olivier Percebois-Garve
wrote:
Hi
I'm puzzled with this :http://pastebin.me/49fef93928aff
(in firebug click on the jquery object, then expand "0")
Using empty() or remove() on the lis of a ul, it seems that jQuery is
"faking" to remove them,
i.e the lis will not be accessible by jQuery anymore, but in reality the
childnodes are still there.
Well, at least that's what I can believe from firebug. (Not sure who's
the liar here jQuery, firebug, or me being dumb)
I'm facing an issue that gets down to that, I really dont understand
whats going on and how to handle it.
(using jQuery 1.2.6)
I hope I am missing the obvious. Am I ?
-Olivier
The LIs you see in Firebug are you the ones you appended at the end of
your script:
$('#u2').append($lis);
The childNodes property is a live collection, it updates as you change
the DOM. Remove the line I mentioned and you'll see the LIs are being
removed correctly, or try appending more items to the list and you'll
see childNodes updating accordingly.
cheers
-- ricardo
Ha !
Thank you very much, "live collection" explains it.
I already did what you said, but I could not make sense out of it.
Is this also solving my other weird issue ? Are object properties also
"live" ?
I had properties becoming "undefined" once I click the logged object :
http://www.screencast.com/users/olivvv/folders/Jing/media/7e598646-3b...
-Olivier
Hello.
I'm having problems with the following code:
var img = [];
//
var o = this.find('img');
o.attr('src', img[n][0]).attr('alt', img[n][1]);
The error I get is:
o.attr("src", img[n][0]).attr is not a function
What am I doing wrong?
Many thanks in advance!
Could not make much sense out of your video either :D
The thing is: when you log an object or element in firebug, it's just
a reference to the object itself, not a snapshot of it at that instant
in time. It will always show the object as it is *now*. Try this in
the console:
x = {a:1};
console.log(x);
x.a = 2;
You'll see that x.a == 2 in the object inspector, not 1. If you
further change x's properties they will continue to be updated in the
inspector. The printed line will not, it will keep showing "Object
a=1", ignore it.
On May 4, 3:30 pm, Olivier Percebois-Garve
wrote:
> Ricardo wrote:
> > On May 4, 11:33 am, Olivier Percebois-Garve
> > wrote:
>
> >> Hi
>
> >> I'm puzzled with this :http://pastebin.me/49fef93928aff
>
> >> (in firebug click on the jquery object, then expand "0")
>
> >> Using empty() or remove() on the lis of a ul, it seems that jQuery is
> >> "faking" to remove them,
> >> i.e the lis will not be accessible by jQuery anymore, but in reality the
> >> childnodes are still there.
> >> Well, at least that's what I can believe from firebug. (Not sure who's
> >> the liar here jQuery, firebug, or me being dumb)
>
> >> I'm facing an issue that gets down to that, I really dont understand
> >> whats going on and how to handle it.
> >> (using jQuery 1.2.6)
>
> >> I hope I am missing the obvious. Am I ?
>
> >> -Olivier
>
> > The LIs you see in Firebug are you the ones you appended at the end of
> > your script:
> > $('#u2').append($lis);
>
> > The childNodes property is a live collection, it updates as you change
> > the DOM. Remove the line I mentioned and you'll see the LIs are being
> > removed correctly, or try appending more items to the list and you'll
> > see childNodes updating accordingly.
>
> > cheers
> > -- ricardo
>
> Ha !
>
> Thank you very much, "live collection" explains it.
> I already did what you said, but I could not make sense out of it.
>
> Is this also solving my other weird issue ? Are object properties also
> "live" ?
> I had properties becoming "undefined" once I click the logged object :
>
> http://www.screencast.com/users/olivvv/folders/Jing/media/7e598646-3b...
>
> -Olivier
Sorry for that I did not see a missed that folder js...
It works now, looks nice in Safari Win, Opera Win. But in IE 8 and
Firefox 3.03 the logo has now that awful link border. How can I change
that?
Txs
Markus
On 4 Mai, 21:09, Karl Swedberg wrote:
> For starters, change the src value in these lines:
>
>
> script>
>