Use
if ($(selector.toString()).children().first().hasClass(""img") {
or
if ($(selector.toString()).children().first().attr("class") == "img") {
NOTE1 : use '==' not '='
NOTE2 : generating dynamic selector is valid and possible too
like this
var i =3;
$("#" + i).show()