jquery 클래스 가져올때 문의
본문
안녕하세요.
클릭한 객체의 클래스를 가져와서 명령할때 아래와 같이 하고 있는데
다른 방법이 있을까요?
예제 입니다.
$(".button").on("click", function() {
var a = $(this).children("span").attr("class"),
b = $(".select").children("img").attr("class");
if (a == "default") {
$("." + b).removeAttr("id"); // << 가져온 클래스를 "." + b 이런식이 아닌 다른 편한 방법이 있나요?
$("." + b).parent("li").children("input").val("");
} else {
$("." + b).removeAttr("id");
$("." + b).attr("id", a);
$("." + b).parent("li").children("input").val(a);
}
});
답변 2
jquery만 보이고 html이 없어서 뭔지 모르겠네요
그게 그거 아닌가요?
아주 약간 개선한다면
sclass='.'+b;
$(sclass).remove~~~
$(sclass).parent~~~
답변을 작성하시기 전에 로그인 해주세요.