1. length 사용
$('element').length == 0; // no element found
<div>
<p>Here is a picture of me: </p>
<img src="images/remy.jpg" />
<div id="debug"></div>
</div>
<script type="text/javascript">
if ($('img').length) { // implies *not* zero
log('We found img elements on the page using "img"');
} else {
log('No img elements found');
}
if ($(':input').length != 0) {
log('Found an input-type element using ":input"');
} else {
log('No input-type elements found');
}
log('Looking for "div img", found ' + $('div').find('img').length);
function log(msg) {
$('#debug').append('<p>' + msg + '</p>');
}
</script>
<span class="greenCheckMark"></span>
$('.clickedElement').live('click',function(){ //does the green check mark exist? if so then do nothing, else $('#listItem).append('<span class="greenCheckMark"></span>'); });
solution-
$('#listItem:not(:has(.greenCheckMark))') .append('<span class="greenCheckMark"></span>');
http://stackoverflow.com/questions/3365181/jquery-detect-if-element-exists
'코드 > JS' 카테고리의 다른 글
프로토타입 심화 (0) | 2013.11.26 |
---|---|
프로토타입체인 (0) | 2013.11.26 |
숫자 3단위마다 콤마 삽임 (0) | 2013.11.21 |
Javascript DOM Ready (0) | 2013.10.23 |
jquery ready (0) | 2013.10.23 |