Problems converting a child object into a JQuery object.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Problems converting a child object into a JQuery object.

Andy Burnett
I am pretty sure this must be a newbie question, but it might help
other beginners.

I have a document like this:

<article>
<h1> something </h1>
<h1> something else </h1>
</article>

In a workspace I execute

tmp1 := 'article' asJQuery.
tmp2 := tmp1 children.
(tmp2 at:2)  fadeOut.

The debugger says
[object HTMLHeadingElement] DNU fadeOut.

I also tried
(tmp2 at:2) asJQuery fadeOut.

Which also didn't work.

My assumption was that the children method returned a collection of
JQuery objects, but that is obviously not right. So, could someone
explain how I convert the collection entries into JQuery objects?

Cheers
Andy
Reply | Threaded
Open this post in threaded view
|

Re: Problems converting a child object into a JQuery object.

Amber Milan Eskridge
Interesting.

| children |
children := '#jtalk' asJQuery children.
children first fadeOut

Does work for me, while:

| children |
children := '#jtalk' asJQuery children.
(children at: 1) fadeOut

Does not.  I have no idea, why that is. However:

| children |
children := '#jtalk' asJQuery children.
(window jQuery: (children at: 1)) fadeOut

Does.

You can give the jQuery methods to any object by doing:
window jQuery: anObject.


On Thu, Dec 22, 2011 at 4:14 AM, Andy Burnett <[hidden email]> wrote:
I am pretty sure this must be a newbie question, but it might help
other beginners.

I have a document like this:

<article>
<h1> something </h1>
<h1> something else </h1>
</article>

In a workspace I execute

tmp1 := 'article' asJQuery.
tmp2 := tmp1 children.
(tmp2 at:2)  fadeOut.

The debugger says
[object HTMLHeadingElement] DNU fadeOut.

I also tried
(tmp2 at:2) asJQuery fadeOut.

Which also didn't work.

My assumption was that the children method returned a collection of
JQuery objects, but that is obviously not right. So, could someone
explain how I convert the collection entries into JQuery objects?

Cheers
Andy

Reply | Threaded
Open this post in threaded view
|

Re: Problems converting a child object into a JQuery object.

Andy Burnett
Ah, the window jQuery: trick is very useful to know!

I assume that my mistake was to treat the children object as if it were a collection.  Clearly, even though it is a JsObjectProxy, it doesn't respond to the at: message correctly.  I shall have to have a closer look at the jQuery methods available for that object.

Just in case anyone has some bright ideas, what I want to do is to iterate over the children collection and set the css based upon the value of the innerText, or maybe innerHTML.  What I had in mind was something like:

children do: [:each| (each.innerHTML contains: 'foo') ifTrue: [:item| item.cssAttribute ... etc]].

Cheers
Andy

On Thu, Dec 22, 2011 at 22:25, Amber Milan Eskridge <[hidden email]> wrote:
Interesting.

| children |
children := '#jtalk' asJQuery children.
children first fadeOut

Does work for me, while:

| children |
children := '#jtalk' asJQuery children.
(children at: 1) fadeOut

Does not.  I have no idea, why that is. However:

| children |
children := '#jtalk' asJQuery children.
(window jQuery: (children at: 1)) fadeOut

Does.

You can give the jQuery methods to any object by doing:
window jQuery: anObject.


On Thu, Dec 22, 2011 at 4:14 AM, Andy Burnett <[hidden email]> wrote:
I am pretty sure this must be a newbie question, but it might help
other beginners.

I have a document like this:

<article>
<h1> something </h1>
<h1> something else </h1>
</article>

In a workspace I execute

tmp1 := 'article' asJQuery.
tmp2 := tmp1 children.
(tmp2 at:2)  fadeOut.

The debugger says
[object HTMLHeadingElement] DNU fadeOut.

I also tried
(tmp2 at:2) asJQuery fadeOut.

Which also didn't work.

My assumption was that the children method returned a collection of
JQuery objects, but that is obviously not right. So, could someone
explain how I convert the collection entries into JQuery objects?

Cheers
Andy