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.

Function for range

Discussion in 'jQuery' started by musicpanda, Sep 10, 2020.

  1. #1
    I can apply a function to all elements of a selection like in
    $("#myid li").each(function(){})
    Code (markup):
    I can also apply a command to a range of childnodes like in
    $('#myid li').slice(0,3).innerHeight(MaxHeight+'px');
    Code (markup):
    But what I want is to combine the two. Unfortunately it is not clear to me how I can apply a function to such a slice range. Can somebody help me?
     
    Solved! View solution.
    musicpanda, Sep 10, 2020 IP
  2. #2
    As the item is passed to your function when running .each, put the innerHeight assignment inside the function as one of the things it does.

    I'm no jQuery expert, I've learned just enough of it to rip it out of websites being screwed over my it's mind-numbingly dumbass approach to EVERYTHING, but I think that would go something like this:

    $("#myid li").slice(0,3).each(function(li){
    	li.innerHeight(MaxHeight+'px');
    	// do your other "each" stuff here
    });
    Code (markup):
    Though this "innerHeight" assignment junk looks like you're using JavaScript to control layout. MOST of the time you shouldn't be doing that in the first place, that's CSS' job. Shame jQuery also dupes people into the derpy "functions for nothing" and other overhead inducing derpitude... by that's why front-end frameworks as a whole amount to little more than ... well, see my signature.
     
    deathshadow, Sep 10, 2020 IP
  3. musicpanda

    musicpanda Greenhorn

    Messages:
    6
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    23
    #3
    Thanks. That works.
     
    musicpanda, Sep 11, 2020 IP