Welcome Guest!

If you do not have an account yet on The Web Squeeze forums, please Register! It’s FREE and there are many benefits:

  • Receive Fast Advice
  • Learn Programming Languages
  • Get Professional Website Reviews
  • Quick Troubleshooting Assistance

> Another Day, Another Challenge... This Time, Selecting Something

This is a discussion on Another Day, Another Challenge... This Time, Selecting Something, within the Javascript section. This forum and the thread "Another Day, Another Challenge... This Time, Selecting Something" are both part of the Frameworks category.

 
Reply to this topicStart new topic
> Another Day, Another Challenge... This Time, Selecting Something, heirachy
cosmicbdog
post Nov 18 2008, 02:40 AM
Post #1


Rapid Squeezer
****

Posts: 146
Joined: 3-July 08


With the following jquery and div I want to show you what I think is a long way to do what I am doing. I'm hoping you can give me a pointer to maybe do this a little better...

CODE
<script type="tex/javascript">

        $j('.ticketOption').click(function(){

            // I'm doing this next selector this way because I'm trying to do something like $j(this+' input:first).attr('checked','true');
           // can heirachy stuff be combined like this? ==> $j(this+' class class')  ?

            $j('#ticketOption'+$j(this).attr('name')).attr('checked', 'true');
    
            // is there a better way?

        });


      // I am trying to get the number value inside the span tags with the class 'number'

      $j('#ticketOption'+$j(this).attr('name')+' ticketPrice number').

</script>

<div class="ticketOption" name="4">


    <input type="radio" name="ticketOption" id="ticketOption4" value="4"/>

    <div class="ticketPrice">
       $
       <span class="number">
            10
       </span>
    </div>            

</div>


Thanks for any ideas
Go to the top of the page
 
+Quote Post
cosmicbdog
post Nov 18 2008, 02:46 AM
Post #2


Rapid Squeezer
****

Posts: 146
Joined: 3-July 08


I'm also trying "$j(this+' span:first').html()" as a way to access the number inside the span of the div clicked.

If you use the html() without anything inside the brackets, does it retrieve the contents of the selection?
Go to the top of the page
 
+Quote Post
Rakuli
post Nov 18 2008, 02:50 AM
Post #3


Squeeze Machine
Group Icon

Posts: 766
Joined: 13-February 08
From: Catching the squeezed drips downunder.


Hi bDog, another day another challenging question. Luckily, I think I can help you with this.

You could benefit from using jQuery contexts. What are contexts? Well, it narrows the scope of selection.

In your example:

CODE
<script type="tex/javascript">

        $j('.ticketOption').click(function(){

            // store the jQuery object for "this" .ticketOption div
            var context = $j(this);

            // Now, using the context stored, get the first input inside of "this" div
            $j('input:first', context).attr('checked', true); // Pass the context as the second argument and jQuery will only look within that context



           // Get the text inside of the span
           var spanValue = $j('span.number:first', context).text();

        });


</script>

<div class="ticketOption" name="4">


    <input type="radio" name="ticketOption" id="ticketOption4" value="4"/>

    <div class="ticketPrice">
       $
       <span class="number">
            10
       </span>
    </div>            

</div>


--------------------
Luke Dingle . com

Turn Over a Playful Leaf on Web Design -- read about the javascript cat
Go to the top of the page
 
+Quote Post
cosmicbdog
post Nov 18 2008, 02:57 AM
Post #4


Rapid Squeezer
****

Posts: 146
Joined: 3-July 08


that is incredible. i've never seen these 'contexts' mentioned. genius in its simplicity
Go to the top of the page
 
+Quote Post
Rakuli
post Nov 18 2008, 02:58 AM
Post #5


Squeeze Machine
Group Icon

Posts: 766
Joined: 13-February 08
From: Catching the squeezed drips downunder.


Yeah, I don't think they're well documented. I found them after digging through jQuery source code when I was writing my first plugin. They're Uber handy <-- I knew I would get the use Uber in conversation one day.


--------------------
Luke Dingle . com

Turn Over a Playful Leaf on Web Design -- read about the javascript cat
Go to the top of the page
 
+Quote Post
c010depunkk
post Nov 18 2008, 07:56 AM
Post #6


Rapid Squeezer
Group Icon

Posts: 199
Joined: 14-February 08
From: Willich, Germany


QUOTE (Rakuli @ Nov 18 2008, 08:58 AM) *
I knew I would get the use Uber in conversation one day.

Ja locker man! Jetzt musst du es nur noch richtig benutzen.....


--------------------
www.c010depunkk.com ~ the hangout of a web developer
Go to the top of the page
 
+Quote Post
japh
post Nov 18 2008, 09:27 AM
Post #7


Squeeze Machine
Group Icon

Posts: 508
Joined: 7-October 08
From: Australia


I guess "uber" isn't directly interchangeable with "super" then, c010depunkk?


--------------------
The more you visit, the more I'll post: http://japheththomson.com/
Go to the top of the page
 
+Quote Post
Rakuli
post Nov 18 2008, 04:51 PM
Post #8


Squeeze Machine
Group Icon

Posts: 766
Joined: 13-February 08
From: Catching the squeezed drips downunder.


QUOTE (c010depunkk @ Nov 18 2008, 11:56 PM) *
Ja locker man! Jetzt musst du es nur noch richtig benutzen.....


I know I wasn't using it right. I was talking about the nerd/geek colloquial usage biggrin.gif


--------------------
Luke Dingle . com

Turn Over a Playful Leaf on Web Design -- read about the javascript cat
Go to the top of the page
 
+Quote Post
cosmicbdog
post Nov 18 2008, 10:06 PM
Post #9


Rapid Squeezer
****

Posts: 146
Joined: 3-July 08


strangely they opened up a club called Uber in the heart of west end brisbane... which if you don't know has always been a very low key subburb / chilled part of the city. I believe it became a dividing factor for many locals to leave the area as a sign of worse to come. lol
Go to the top of the page
 
+Quote Post
If you found The Web Squeeze to be helpful, please donate so we can keep this site FREE, FRESH, and fortified with Web Design & Development info!
Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No New Posts   9 1christopher 436 23rd February 2008 - 01:09 PM
Last post by: 1christopher
No New Posts   3 unitedcraig 207 24th April 2008 - 04:40 PM
Last post by: unitedcraig
No new   24 welshstew 493 2nd May 2008 - 04:15 PM
Last post by: Simon
No new   14 Linda 241 28th May 2008 - 12:44 PM
Last post by: Jacob
No New Posts 7 Linda 260 4th June 2008 - 04:32 PM
Last post by: unitedcraig