quick question about jquery

  • mindfullsilence
  • Professor
  • Professor
  • User avatar
  • Posts: 854

Post 3+ Months Ago

fairly simple, can you use the "*" css selector in jquery? I need to look through all of my code for a class and remove that class. It'll be applied to several different tags.

I was thinking something like this:

JAVASCRIPT Code: [ Select ]
 
$("html *").removeClass("active");
 
 
  1.  
  2. $("html *").removeClass("active");
  3.  
  4.  
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • mindfullsilence
  • Professor
  • Professor
  • User avatar
  • Posts: 854

Post 3+ Months Ago

nevermind, shoulda looked first:


http://docs.jquery.com/Selectors/all
  • mindfullsilence
  • Professor
  • Professor
  • User avatar
  • Posts: 854

Post 3+ Months Ago

okay, since I pretty much solved that question on my own, I'll post my next one here so I don't waste space. I just looked around the jquery documentation and I can't seem to figure out how to get the od of an element. I have set up id's on my links that correspond with id's for my images. The id's are equivalent to the index number of an array. so this is what is generated, essentially:

JAVASCRIPT Code: [ Select ]
$.ajax({
   type: "GET", url: "js/img.xml", dataType: "xml",error: function(){alert('Error loading XML document');},
   success: function(xml) {
      $(xml).find('#web image').each(function(){
         var imagenum = $(xml).find('#web image').index(this);
         $("#webthumblist").append('<li><a href="#" id="' + imagenum +'" ></a></li>');
      });
   }
});
 
  1. $.ajax({
  2.    type: "GET", url: "js/img.xml", dataType: "xml",error: function(){alert('Error loading XML document');},
  3.    success: function(xml) {
  4.       $(xml).find('#web image').each(function(){
  5.          var imagenum = $(xml).find('#web image').index(this);
  6.          $("#webthumblist").append('<li><a href="#" id="' + imagenum +'" ></a></li>');
  7.       });
  8.    }
  9. });
  10.  


creates this html:
HTML Code: [ Select ]
<div id="webthumbcontainer">
            <ul id="webthumblist">
           
            <li>
                <a href="#" id="[b]0[/b]"></a>
            </li>
            <li>
                <a href="#" id="[b]1[/b]"></a>
            </li>
            <li>
                <a href="#" id="[b]2[/b]"></a>
            </li>
            <li>
                <a href="#" id="[b]3[/b]"></a>
            </li>
 
        </ul>
</div>
 
  1. <div id="webthumbcontainer">
  2.             <ul id="webthumblist">
  3.            
  4.             <li>
  5.                 <a href="#" id="[b]0[/b]"></a>
  6.             </li>
  7.             <li>
  8.                 <a href="#" id="[b]1[/b]"></a>
  9.             </li>
  10.             <li>
  11.                 <a href="#" id="[b]2[/b]"></a>
  12.             </li>
  13.             <li>
  14.                 <a href="#" id="[b]3[/b]"></a>
  15.             </li>
  16.  
  17.         </ul>
  18. </div>
  19.  


some other functions also grab the link to the images and puts them in a seperate div on the page with corresponding id's like so:

HTML Code: [ Select ]
<div id="imagecontainer">
    <img src="tadesign/images/carcare.jpg" id="[b]0[/b]">
    <img src="tadesign/images/monster.jpg" id="[b]1[/b]">
    <img src="tadesign/images/rantingbill.jpg" id="[b]2[/b]">
    <img src="tadesign/images/voltecsite.jpg" id="[b]3[/b]">
</div>
 
  1. <div id="imagecontainer">
  2.     <img src="tadesign/images/carcare.jpg" id="[b]0[/b]">
  3.     <img src="tadesign/images/monster.jpg" id="[b]1[/b]">
  4.     <img src="tadesign/images/rantingbill.jpg" id="[b]2[/b]">
  5.     <img src="tadesign/images/voltecsite.jpg" id="[b]3[/b]">
  6. </div>
  7.  


when the user clicks on the generated link, I need to add a class to all elements with the same id. So in this case if I clicked on the second link, which has the id "1", jquery would add the class "active" to both the link and the image with id="1". The problem is, I can't write this function for each id number, because there's no way to tell how many images will be in the page at any given time. So I have to have the javascript read the id attribute, then look through the html for all elements with the same id, and give each of them a class.
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • User avatar
  • Posts: 2733
  • Loc: Nashville, TN

Post 3+ Months Ago

so maybe something like this? I'm running out of time to test, but maybe this is the direction you need...

Code: [ Select ]
<a href="#" onClick="$('# + " + this.id + "').each( function(){ $(this).addClass('active'); });" />

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 100 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.