0
var standard_anchor = new Array(); 
    standard_anchor[0] = "http://1-9-9-1.tumblr.com/";
    standard_anchor[1] = "http://www.egs.edu/faculty/jean-baudrillard/articles/simulacra-and-simulations-viii-the-implosion-of-meaning-in-the-media/";
    standard_anchor[2] ="http://www.bopsecrets.org/images/sos.pdf";
    standard_anchor[3] ="http://www.amazon.com/Murakami-Versailles-Laurent-Bon/dp/2915173729";
    standard_anchor[4] ="http://www.gagosian.com/exhibitions/2011-06-27_takashi-murakami/";
    standard_anchor[5] ="http://www.chloepiene.com/work.html";
    standard_anchor[6] ="#";
    standard_anchor[7] ="http://en.wikipedia.org/wiki/Takashi_Murakami#Market_Value";
    standard_anchor[8] ="http://www.imdb.com/title/tt0094625/";
    standard_anchor[9] ="http://en.wikipedia.org/wiki/Icarus";
    standard_anchor[10] ="http://gundam.wikia.com/wiki/Heero_Yuy";
    standard_anchor[11] ="http://www.amazon.com/Mobile-Suit-Gundam-Chars-Counterattack/dp/B000KF0P2I";
    standard_anchor[12] ="http://gundam.wikia.com/wiki/Char_Aznable";
    standard_anchor[13] ="http://gundam.wikia.com/wiki/Zeta_Gundam";
    standard_anchor[14] ="http://en.wikipedia.org/wiki/Genocide";
    standard_anchor[15] ="http://www.guardian.co.uk/uk/2011/aug/09/mark-duggan-police-ipcc";
    standard_anchor[16] ="http://en.wikipedia.org/wiki/Race_and_the_War_on_Drugs";
    standard_anchor[17] ="http://www.imdb.com/title/tt0259484/";

    var standard = function(){ $.each(standard_anchor,function(value){ return value }); };



$(document).ready(function(){


    //lazy load
    $(function( lazyload ){  

    $("#content img").lazyload({ threshold : 5,  effect : "fadeIn" });

    });

    //anchor handler


        /*  should  replace all a href values with reversed iterated standard anchor data   */
             $('a [href]').reverse().each(function(i){$(this).attr('href', standard_anchor[i])});






//end
});

for the record if this is formatted improperly I've been teaching my self all this with no help until last night from anyone.

I hoped that this would work to populate all of the href values in my html with these array values however this doesn't work, I'm unclear on the finer points of alot of this but on my own I that that a variable that returned the array values to a function that reverse traversed my anchor tags would be the most efficient means to accomplish this. I asked a similiar question to this and was advised to reformat my standard variable to it's current state(i nested it in a jQuery method for no reason apparently) as well as to reformat the statement that selected and traversed the anchor tags(which I did) I now humbly ask what is the reason that this doesn't work?

5
  • 1
    Have you tried closing the gap between a and [href]? As it is the space implies selection of an element with the href attribute that's a descendent of an a. Try using $('a[href]') instead. Commented Aug 10, 2011 at 16:41
  • thanks I didn't even see that I'd done that. Commented Aug 10, 2011 at 16:43
  • @Melchizedek, reposted my comment as an answer. Commented Aug 10, 2011 at 16:48
  • @Šime Vidas, why should I? and what's so ridiculous about it? I wrote that way so that I could keep track of each links position in the array as it relates to the number of blog posts, what would you suggest? Commented Aug 10, 2011 at 17:09
  • @Melchizedek You are writing the same name (which is a rather long name in your case) 18 times in a row. This is called redundancy, and should be avoided (if possible). Read about the DRY principle. If you require information about the index of each URL, I recommend comments: i.imgur.com/w29l4.png Commented Aug 10, 2011 at 17:27

3 Answers 3

2

The problem is simply the incorrect selector: $('a [href]'), should be $('a[href]').

The former selects an element with an href attribute that's a descendent of an a element, whereas the latter selects all a elements with the href attribute.

Sign up to request clarification or add additional context in comments.

Comments

0

I bet the value of i is not correct.

Try:

var i = $('a [href]').length
$('a [href]').reverse().each(function(){$(this).attr('href', standard_anchor[i--])});

Comments

0

I'm pretty sure your selector is just wrong here. Try this instead:

$('a').reverse().each(function(i){$(this).attr('href', standard_anchor[i])});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.