Q:

How to compare event and HTML tag in Javascript

I'm trying to compare these codes to boolean value.
HTML
<a href="#" id="like">
    <i class="fa fa-thumbs-o-up fa-fw"></i>
</a>

jQuery
$('#like').on('click', function(event) {

    ...

    var htmlTag = '<i class="fa fa-thumbs-o-up fa-fw"></i>';
    var isLike = event.target.closest('#like').innerHTML == htmlTag;

    if (isLike) {
        console.log('true');
    } else {
        console.log('false');
    }

    ...

});

But it's going to false, In fact it should be true. Why?
Thanks for every answers.

A:

You should use .html() method in order to return the html of hyperlink.

$('#like').on('click', function(event) {
    var htmlTag = 'Like<i class="fa fa-thumbs-o-up fa-fw"></i>';
    var isLike = $(this).html().trim() == htmlTag;
    if (isLike) {
        console.log('true');
    } else {
        console.log('false');
    }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a  id="like">
  Like<i class="fa fa-thumbs-o-up fa-fw"></i>
</a>

