0

Getting an [object Object] error on linkOne within $related. I tried using JSON.stringify(), but that didn't seem to work. Below is the code thusfar:

var $secondParagraph = $('.entry-content > p:eq(1)');

var linkOneLink = $(".pagealignleft > .bottom > a:eq(0)").attr("href");
var linkOneText= $(".pagealignleft > .bottom > a:eq(0) > span:eq(0)");
var linkOne = ['<a href=\"' +  linkOneLink + '\">' + linkOneText + '</a>'].join('').toString();

var $related = [
    '<div class="relatedOne">',
  '<p>',
  '<br />',
  '<span class="optTitle">Related Content: </span>',
  linkOne,
  ', ',
  '<a href="">the Collection</a> ',
  '</p>',
  '</div>'
].join('');


if ($secondParagraph.length) {
    $secondParagraph.append($related);
}
$(".optTitle").css({"color":"#dd4b39","font-size":"16px"});
$(".relatedOne a").css({"color":"#555","font-size":"16px","text-decoration":"underline"});
Ao C
  • 127
  • 1
  • 9

2 Answers2

2
var linkOneText= $(".pagealignleft > .bottom > a:eq(0) > span:eq(0)");

This returns a jQuery object. I think you're trying to get a string value here, maybe the contents of this element? So maybe add .html() or .text() at the end?

Neil S
  • 2,304
  • 21
  • 28
1

You aren't getting the contents of the link, just the link itself. Change

var linkOneText= $(".pagealignleft > .bottom > a:eq(0) > span:eq(0)");

to

var linkOneText= $(".pagealignleft > .bottom > a:eq(0) > span:eq(0)").text();

js1568
  • 7,012
  • 2
  • 27
  • 47