Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting document.getElementsByClassName to Jquery

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.

like image 770
User999999 Avatar asked May 14 '14 07:05

User999999


1 Answers

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();
});
like image 167
Felix Avatar answered Sep 24 '22 16:09

Felix