Converting document.getElementsByClassName to Jquery

javascript, jquery

Solution

You need to use another dot `.` without space to target elements by multiple classes:

$(".glyphicon.glyphicon-comment").tooltip();

and apply the same way for `.each()` method:

$(".glyphicon.glyphicon-comment").each( function() {
    $(this).tooltip();
});

Problem

I have the following piece of code, that i can't seem to convert to Jquery could someone help me out. Pure JS working code: ``` var elements = document.getElementsByClassName("glyphicon glyphicon-comment"); for (var i = 0, length = elements.length; i < length; i++) { $('#' + elements[i].id).tooltip(); } } ``` My Jquery Attempts (both not working): Attempt 1: ``` $(".glyphicon glyphicon-comment").tooltip(); ``` Attempt 2: ``` $(".glyphicon glyphicon-comment").each( function() { $(this).tooltip(); }); ``` Example of the button: ``` <span class="glyphicon glyphicon-comment" data-toggle="tooltip" data-placement="left" id="commentTask1" data-original-title="This is comments"></span> ``` Could someone spot the error i've made? Thnx for your efforts.

Original source