1

I'm having trouble getting the following code to pass JSHint

for (var i = 0; i < navLinks.length; i++) {
  navLinks[i].addEventListener('click', loadPageContent);
}

function loadPageContent(e) {
    e.preventDefault();
    var pageURL = this.attributes.href.value;  <-- Possible strict violation

    loadContent(pageURL, function() {
        var pageData = pages[pageURL.split('.')[0]];

        // Create a new history item.
        history.pushState(pageData, pageData.title, pageURL);
    });
}

I know it's because "this" in a function declaration, but I don't know how to fix it, can anyone help? Thanks!

Tachun Lin
  • 942
  • 3
  • 11
  • 18
  • possible duplicate of [Why is JSHINT complaining that this is a strict violation?](http://stackoverflow.com/questions/7688765/why-is-jshint-complaining-that-this-is-a-strict-violation) – Radu Bompa Feb 10 '14 at 09:53
  • You can find an answer here: http://stackoverflow.com/questions/7688765/why-is-jshint-complaining-that-this-is-a-strict-violation . A "possible" strict violation will most likely not cause an error, so you can use the code as it is. You can also replace 'this' with 'event.currentTarget'. – Radu Bompa Feb 10 '14 at 09:55

0 Answers0