[jQuery] Re: Explaining this or .this or .this()

2007-11-29 Thread Priest, James (NIH/NIEHS) [C]

I think you could do something like:

$("div").each(function() {
$(this).css('color', 'red');
}); 

Basically all this is doing is looping over each DIV on your page and at
each DIV (this) it's changing the color of that div.  

Here is another one I did for a recent project - I have a list of div's
each with a 'container' class:

Item 1
Item 2
Item 3
Item 4
Item 5

I wanted to highlight the background of each div as the user rolled
their mouse over them - this was basically a hack for IE6:

$('div.container').hover(function() {
$(this).addClass('pretty-hover');
}, function() {
$(this).removeClass('pretty-hover');
});

Again - this is just saying - when you hover your mouse over THIS
div.container - add a class.  When you move your mouse off of it -
remove the class.

I think if you tinker around with stuff like this a bit - it start to
click.

Jim

> -Original Message-
> From: FrankTudor [mailto:[EMAIL PROTECTED] 

> I can't 'write' or 'create' in the environment i working.  Could you
> maybe work the example so that it outputs to the screen.  I can make a
> sample file with 'div' tags point to my jquery.js file.  I have done
> jquery scripts without the 'this' part and I would attempt to change
> it but 'this' is a stumper for me.
> 


[jQuery] Re: Explaining this or .this or .this()

2007-11-29 Thread FrankTudor

I fell like I could get this concept.  I'm close.  I think I need to
create something, but i don't no 'this' so I don't know how to use it.

Does that example work that you posted...where does it log?  to the
current directory?

I can't 'write' or 'create' in the environment i working.  Could you
maybe work the example so that it outputs to the screen.  I can make a
sample file with 'div' tags point to my jquery.js file.  I have done
jquery scripts without the 'this' part and I would attempt to change
it but 'this' is a stumper for me.

Frank

On Nov 29, 1:42 pm, "Josh Nathanson" <[EMAIL PROTECTED]> wrote:
> > So then it pulls part of a function?
>
> > Is 'this' in the example you made pulls $("div") or $("div").each
>
> It doesn't pull part of a function...it pulls the object within which the
> function is executing.
>
> In my example, the function is "each", and the object within which it is
> executing is the jQuery object (which is an array of div elements) returned
> by $("div").  So, "this" would refer to the current div element which is
> being iterated.
>
> It's not easy to wrap your mind around it, it definitely takes some time and
> experimentation to see how it works.
>
> -- Josh
>
> - Original Message -
> From: "FrankTudor" <[EMAIL PROTECTED]>
> To: "jQuery (English)" 
> Sent: Thursday, November 29, 2007 11:32 AM
> Subject: [jQuery] Re: Explaining this or .this or .this()
>
> > Frank
>
> > On Nov 29, 12:38 pm, "Josh Nathanson" <[EMAIL PROTECTED]> wrote:
> >> I'll give it a shot...and please gurus correct any mistakes here..."this"
> >> refers to the object context within which it is referenced at runtime.
>
> >> So, if you have a bunch of divs:
>
> >> $("div").each(function() {
> >> console.log(this);
>
> >> });
>
> >> You will see in the console each of the divs as it loops over them.
>
> >> Every javascript function runs within the context of some object -- at
> >> the
> >> highest level this is the window (global) object.
>
> >> To understand context and scoping better, I highly recommend checking out
> >> John Resig's book "Advanced JavaScript Techniques," it cleared up a lot
> >> of
> >> confusion for me.
>
> >> -- Josh
>
> >> - Original Message -
> >> From: "FrankTudor" <[EMAIL PROTECTED]>
> >> To: "jQuery (English)" 
> >> Sent: Thursday, November 29, 2007 8:14 AM
> >> Subject: [jQuery] Explaining this or .this or .this()
>
> >> > There is a concept I am struggling with and I am not sure how to
> >> > approach it.  I am trying to understand:
>
> >> > .this
>
> >> > I don't know if an explanation or an example would be best. But I want
> >> > to understand it.
>
> >> > I have tried to read an explanation and it doesn't make sense.
>
> >> > Can someone help me?
>
> >> > Frank


[jQuery] Re: Explaining this or .this or .this()

2007-11-29 Thread Josh Nathanson



So then it pulls part of a function?

Is 'this' in the example you made pulls $("div") or $("div").each


It doesn't pull part of a function...it pulls the object within which the 
function is executing.


In my example, the function is "each", and the object within which it is 
executing is the jQuery object (which is an array of div elements) returned 
by $("div").  So, "this" would refer to the current div element which is 
being iterated.


It's not easy to wrap your mind around it, it definitely takes some time and 
experimentation to see how it works.


-- Josh

- Original Message - 
From: "FrankTudor" <[EMAIL PROTECTED]>

To: "jQuery (English)" 
Sent: Thursday, November 29, 2007 11:32 AM
Subject: [jQuery] Re: Explaining this or .this or .this()





Frank

On Nov 29, 12:38 pm, "Josh Nathanson" <[EMAIL PROTECTED]> wrote:

I'll give it a shot...and please gurus correct any mistakes here..."this"
refers to the object context within which it is referenced at runtime.

So, if you have a bunch of divs:

$("div").each(function() {
console.log(this);

});

You will see in the console each of the divs as it loops over them.

Every javascript function runs within the context of some object -- at 
the

highest level this is the window (global) object.

To understand context and scoping better, I highly recommend checking out
John Resig's book "Advanced JavaScript Techniques," it cleared up a lot 
of

confusion for me.

-- Josh

- Original Message -
From: "FrankTudor" <[EMAIL PROTECTED]>
To: "jQuery (English)" 
Sent: Thursday, November 29, 2007 8:14 AM
Subject: [jQuery] Explaining this or .this or .this()

> There is a concept I am struggling with and I am not sure how to
> approach it.  I am trying to understand:

> .this

> I don't know if an explanation or an example would be best. But I want
> to understand it.

> I have tried to read an explanation and it doesn't make sense.

> Can someone help me?

> Frank 




[jQuery] Re: Explaining this or .this or .this()

2007-11-29 Thread FrankTudor

So then it pulls part of a function?

Is 'this' in the example you made pulls $("div") or $("div").each

Frank

On Nov 29, 12:38 pm, "Josh Nathanson" <[EMAIL PROTECTED]> wrote:
> I'll give it a shot...and please gurus correct any mistakes here..."this"
> refers to the object context within which it is referenced at runtime.
>
> So, if you have a bunch of divs:
>
> $("div").each(function() {
> console.log(this);
>
> });
>
> You will see in the console each of the divs as it loops over them.
>
> Every javascript function runs within the context of some object -- at the
> highest level this is the window (global) object.
>
> To understand context and scoping better, I highly recommend checking out
> John Resig's book "Advanced JavaScript Techniques," it cleared up a lot of
> confusion for me.
>
> -- Josh
>
> - Original Message -
> From: "FrankTudor" <[EMAIL PROTECTED]>
> To: "jQuery (English)" 
> Sent: Thursday, November 29, 2007 8:14 AM
> Subject: [jQuery] Explaining this or .this or .this()
>
> > There is a concept I am struggling with and I am not sure how to
> > approach it.  I am trying to understand:
>
> > .this
>
> > I don't know if an explanation or an example would be best. But I want
> > to understand it.
>
> > I have tried to read an explanation and it doesn't make sense.
>
> > Can someone help me?
>
> > Frank


[jQuery] Re: Explaining this or .this or .this()

2007-11-29 Thread Josh Nathanson


I'll give it a shot...and please gurus correct any mistakes here..."this" 
refers to the object context within which it is referenced at runtime.


So, if you have a bunch of divs:

$("div").each(function() {
   console.log(this);
});

You will see in the console each of the divs as it loops over them.

Every javascript function runs within the context of some object -- at the 
highest level this is the window (global) object.


To understand context and scoping better, I highly recommend checking out 
John Resig's book "Advanced JavaScript Techniques," it cleared up a lot of 
confusion for me.


-- Josh




- Original Message - 
From: "FrankTudor" <[EMAIL PROTECTED]>

To: "jQuery (English)" 
Sent: Thursday, November 29, 2007 8:14 AM
Subject: [jQuery] Explaining this or .this or .this()




There is a concept I am struggling with and I am not sure how to
approach it.  I am trying to understand:

.this

I don't know if an explanation or an example would be best. But I want
to understand it.

I have tried to read an explanation and it doesn't make sense.

Can someone help me?

Frank