udacity/nd032-c3-asynchronous-programming-with-javascript-project-starter

renderAt throws an error length of null

fanyui opened this issue · 2 comments

function renderAt(element, html) takes in the parameters elementEither the id or the class name of the element at which to render and the HTML the actual content to render the check inside

	if (element.match(/^\./).length) {
		node = document.getElementsByClassName(element)
	}

	if (element.match(/^#/).length) {
		node = document.getElementById(element)
	}

Either of the condition will always fail ie when the id is supplied the class will fail as the evaluation
element.match(/^#/).length will be evaluating length of null the reverse is true.

I am also experiencing the same issue and had to adjust it to execute the code. Here is what I did:

if (element.match(/^\./) !== null) {
    node = document.getElementsByClassName(element.slice(1))
}

if (element.match(/^#/) !== null) {
    node = document.getElementById(element.slice(1))
}

I had to remove the first character as the passed starts with either a # or . which are not compatible with the getElementByID and getElementByClassName respectively.

Hi,
Though we are a little late to respond, we encourage such user-specific issues to be raised on the Knowledge hub, so that our experienced mentors can chime in and new students can also learn from the discussion thread.
Thank you