1

The below function is returning [object Object] instead of the html/text in the element, only on first click. Every subsequent click returns the element text. I've tried using .html and .text - that doesn't work. The problem seems to be when I add the onclick function, because if I remove the onclick and simply use $("#id").html() with no click function, it works.

 +  $('.education-modal-link').on('click', function(e) {

    e.preventDefault();

    var modalCaptionTextCall = $(this).prev('div').html();

    $('div.modal-caption').eq(0).html(modalCaptionTextCall); 
    })

What am I doing wrong?

see problem at this link: http://johnhoich.com/homepage Scroll down to education section and click on an education content card.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Mike
  • 59
  • 2
  • 7
  • I'm only guessing since there is not enough info but it looks like it is related to `featherlight` lib being used as the first `click` on the link creates the modal as the DOM element - in this case only one `click` event is called. And then after this initial `click` event being called when you click on the link you get a chain of `click` events, you can check this in the Chrome Dev Tools debugger. – Ignacy Kasperowicz Jan 15 '17 at 20:51
  • I think you're right - how would I go about fixing this? – Mike Jan 15 '17 at 21:58
  • @IgnacyKasperowicz how should I fix this? – Mike Jan 16 '17 at 03:48
  • Would you create a JSBin to reproduce this issue? It would be easier to help if we can edit JS/HTML/CSS and not search for everything through all JS files on the page. – Ignacy Kasperowicz Jan 16 '17 at 11:51
  • @IgnacyKasperowicz I figured it out! Your advice helped me out a little bit... I moved the function to a different place in the file. I moved it so the function would be included in one click event... where data-featherlight is fetched. Thanks for your tip... – Mike Jan 16 '17 at 22:02
  • Awesome, I think you should write the explanation as an answer and accept it yourself. In case someone else having same issues could find your solution. – Ignacy Kasperowicz Jan 17 '17 at 08:58
  • I will asap - it doesn't let me answer my question until a certain amount of time has passed – Mike Jan 19 '17 at 05:51

1 Answers1

1

The problem was that the click event was outside of the first click event - so the [object] wasn't being called on the first click, but was still being called on every click after that.

I had to locate the click event in the monstrous JS file and add the function inside of it.

Mike
  • 59
  • 2
  • 7