Question

I am gettings TypeError: 'undefined' is not a function (evaluating 'document.getElementByClassName("selceted")') when trying to get the class name or ID of the div. and I cannot figure out why. The array/nodelist is NOT empty, it has ALL the data in from every timeline-item post, and only 1 has the class of selected so how do I get only that element?

Here is my code so far:

if($.inArray(postdate, post_image_dates)){
    var posts = $(".timeline-item");
    posts.removeClass("selected");
    var matchedPost = posts.filter("[data-date='" + postdate + "']");

    if(matchedPost.length > 0){
        matchedPost.addClass("selected");

        var more_post_content = document.createElement('div');
        more_post_content.id = 'more_post_content';

        var ul = document.createElement('ul');
        var li = document.createElement('li');
        li.innerHTML = '<a href="#"><img src="' + postdata + '"/></a>';

        ul.appendChild(li);
        more_post_content.appendChild(ul);
        var elementArray;

        elementArray = [].slice.call(matchedPost, 0);
        console.log(elementArray);
        if($.inArray('selected', elementArray)){
            var select = document.getElementByClassName("selceted");
        }
    }
Was it helpful?

Solution

You need to change getElementByClassName to getElementsByClassName also the class name that you are used is incorrect.

if($.inArray('selected', elementArray)){
   var select = document.getElementsByClassName("selected");
   //..............................^................^.........
}

OTHER TIPS

Just some spelling mistakes here

document.getElementByClassName("selceted");

change to

document.getElementsByClassName("selected");

Syntax

elements = document.getElementsByClassName(names); // or:
elements = rootElement.getElementsByClassName(names);

Example

Get all elements that have a class of 'test'

document.getElementsByClassName('test');

Try to change selceted to selected

and getElementByClassName to getElementsByClassName, final select variable should be:

if($.inArray('selected', elementArray)){
    var select = document.getElementsByClassName("selected");
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top