如何检查点击的元素是否也有类x?

时间:2018-05-11 20:09:51

标签: javascript jquery html

这是我的代码:

doc.on("click", ".add_your_qora", function(e){
     // in here I need to know, has this element also "myclass" class too?
})

正如我在代码中所评论的那样,我需要知道,.add_your_qora元素是否还有myclass?我该如何确定?

3 个答案:

答案 0 :(得分:0)

您可以使用Element.classList.contains

没有jQuery的示例:

user.FirstName = model.FirstName;
user.LastName = model.LastName;
user.Address1 = model.Address1;
user.Address2 = model.Address2;
user.City = model.City;
user.State = model.State;
user.Zip = model.Zip;
user.Company = model.Company;
user.Country = model.Country;
user.SetDisplayName();
user.SetProfileID();

_dbContext.Attach(user).State = EntityState.Modified;
_dbContext.SaveChanges();

答案 1 :(得分:-1)

您可以使用$(this).hasClass('myClass');

答案 2 :(得分:-1)

您可以使用className属性,例如

myFunction(){
var target = document.getElementById('the_div_id');
if(target.className === "myclass"){
    alert("it has myclass");
}
}

您还可以查看此https://cloud.google.com/logging/docs/view/overview#custom-fields,看看这是否对您有帮助。