1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Use a Class instead of a Function help!!!!

Discussion in 'jQuery' started by cyimking, Jul 18, 2013.

  1. #1
    Hello,

    I am trying to load a script but i do not want to include a script just use the class.

    Example:

    Instead of doing -
    
    <div><script type="text/javascript">rain('Money');</script></div>
    
    Code (markup):
    I want to do this:
    
    <div class="rain">Money</div>
    
    Code (markup):
    And the effect will be the same.
     
    cyimking, Jul 18, 2013 IP
  2. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #2
    Not really sure what you mean. What does the rain() function entail?
     
    HuggyStudios, Jul 19, 2013 IP
  3. jimmyt200388

    jimmyt200388 Well-Known Member

    Messages:
    192
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    130
    #3
    $(document).ready(function(){
      rain();
    });
    Code (markup):
     
    jimmyt200388, Jul 24, 2013 IP
  4. cyimking

    cyimking Member

    Messages:
    14
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    31
    #4
    Ok sorry for the late response, but i figure some stuff out. However, i am having a bug with the new updated code.

    
    $("document").ready(function(){
    $(".rb").each(function(e){
    var classes = "cyimking_rainbow" + parseInt(e+1);
          rainbownameload(classes);
      });
    });
    
    Code (markup):
    Specially, this is how i will load the code in html
    
    <span class="cyimking_rainbow1 rb">Cyimking</span>
    <br/>
    <span class="cyimking_rainbow2 rb">hello world!</span>
    <br/>
    
    Code (markup):
    Then it will do a rainbow effect. However, this is the error that i am having:
    - I simply want to use ONE class instead of mutliple classes. So instead of cyimking_rainbow1 , cyimking_rainbow2,; I would like cyimking_rainbow.

    - This is the error.
    
    <span class="cyimking_rainbow1 rb">Cyimking</span> <br/>
    <span class="cyimking_rainbow1 rb">hello world!</span> <br/>
    
    Code (markup):
    Instead of : Cyimking , hello world!
    Its doing this: Cyimkinghello world!, Cyimkinghello world!


    AGAIN, i am using this for my forum board and when i give the class to a group, it take ALL the objects that uses this class and replace each instance of that object per object...

    So instead of Cyimking, Cyimking, Cyimking, Admin..
    Its doing this: CyimkingCyimkingCyimkingAdmin, CyimkingCyimkingCyimkingAdmin,CyimkingCyimkingCyimkingAdmin,CyimkingCyimkingCyimkingAdmin
     
    cyimking, Aug 7, 2013 IP
  5. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #5
    e would always be '1' because it's an object for the element, NOT the number of elements counted! You'll need to maintain a separate counter, which is why I'd NOT be wasting time with jQuery's COMPLETELY POINTLESS 'each' function. (though I consider jquery on the whole to be pointless idiotic bloat)

    I'd also toss it in an anonymous function so it's not polluting the namespace. Just run this right before </body> (instead of wasting time waiting for onload)

    (function(){
    	var
    		rbList = $('.rb'),
    		count = 0;
    	for (var rb in rbList) {
    		rb.className.=' cyimking_rainbow' . ++count;
    	}
    })();
    Code (markup):
    Though I'd probably swing an axe at the fat bloated steaming pile of manure known as jQuery. For all the 'savings' it allegedly provides in writing code, it's horrifically offset by being fully half my ideal size limit for a page template (HTML+CSS+IMAGES+SCRIPTS!)
     
    deathshadow, Aug 18, 2013 IP
  6. cyimking

    cyimking Member

    Messages:
    14
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    31
    #6
    Thanks for your help but i am getting an error on line 6.
     
    cyimking, Aug 19, 2013 IP
  7. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #7
    Gah, I'm switching languages too often... stupid typo. Should be:

    rb.className += ' cyimking_rainbow' + (++count);
     
    deathshadow, Aug 20, 2013 IP