Getting value from key pair value into appended property using jQuery

Posted by Neil on Stack Overflow See other posts from Stack Overflow or by Neil
Published on 2010-04-02T10:55:48Z Indexed on 2010/04/02 11:03 UTC
Read the original article Hit count: 259

Filed under:
|

How do I get the value from a key pair value into the rel property of an anchor tag?

When I split the code to put the value in the correct place it doesn't work, the end of the a tag would appear on screen instead value wouldn't be applied. When I look at the resulting code in console in Firebug the rel and href swapped order so the rel is first.

The 'key' should be and is in the correct location but the 'value' needs to be applied to the rel attribute.

What am I doing wrong?

$(function() {
 var obj = {"firstThing":"4","secondThing":"6","aThirdThing":"2","anotherThing":"3","followedByAnother":"4"};

 $.each(obj, function(key,value) {

  $('#newmine').append("<li class='tagBlocks'>","<a href='#' rel=''>",value," ",key);
 });
});

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JavaScript