1. Description
jQuery(":image") : type이 image로 설정된 Element들을 찾는다([type="image"]와 동일하다).
2. Example
#1버튼을 누르면 [type="image"]를 찾아서 border스타일을 변경한다. 버튼을 클릭할 때마다 해당 스타일이 토글된다.
Amazon | ||
Tesla | Netflex | |
My Big Company | My Great Company | My Awesom Company |
[HTML Code]
[//HTML Code]
3. Code
더보기
<!-- ---------------------------------------------------------
--
-- Author: 1q74.tistory.com
--
--------------------------------------------------------- -->
<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8">
<title>[1q74.tistory.com] javascript/jquery/selector/image</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script>
</head>
<body>
<div name="_1q74-example-root">
<div name="_1q74-example-1">
<table name="bigtech" border="1">
<tr>
<td><input type="image" src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png"/>Google</td>
<td><input type="image" src="https://upload.wikimedia.org/wikipedia/commons/thumb/a/a9/Amazon_logo.svg/603px-Amazon_logo.svg.png"/>Amazon</td>
<td>Facebook</td>
</tr>
<tr>
<td>Tesla</td>
<td>Twitter</td>
<td>Netflex</td>
</tr>
<tr>
<td>My Big Company</td>
<td>My Great Company</td>
<td>My Awesom Company</td>
</tr>
</table>
</div>
<div name="_1q74-example-bottom">
<br/>
<button name="btn-find">#1. $("[name='_1q74-example-1'] [type='image']")</button>
</div>
</div>
<hr/>
<h5>[HTML Code]</h5>
<div name="_1q74-source">
</div>
<h5>[//HTML Code]</h5>
<script>
var elements = $("[name='_1q74-example-1'] [type='image']");
var btnFind = $("[name='btn-find']");
btnFind.click(function() {
if(!elements.is("[style]")) {
elements.css("border", "3px Chocolate dotted");
} else {
elements.removeAttr("style");
}
});
// ------------------------------------------------------
// 소스출력
// ------------------------------------------------------
var textSource = $("[name='_1q74-source']");
var exampleHtml = $("[name='_1q74-example-root']").html();
var specialCharLines = textSource.text(exampleHtml).html().split("\n");
textSource.html(specialCharLines.join("<br/>").replaceAll("\t", " "));
</script>
<style>
[name="_1q74-example-root"] {
min-height: 170px;
}
[name="_1q74-example-1"] {
min-height: 140px;
}
[name="_1q74-example-root"] [type="image"]{
width: 100px;
}
[name="_1q74-example-1"] td {
min-width: 100px;
}
[name|="_1q74-example"] button
,[name="_1q74-source"] button {
background: lightgray;
border: 5px outset;
min-height: 30px;
}
[name|="_1q74-example"] button:active
,[name="_1q74-source"] button:active {
border: 2px inset;
min-height: 30px;
}
</style>
</body>
</html>
4. File
5. See also
useversal-selector, jquery-extensions
6. Reference
https://api.jquery.com/image-selector/
'JavaScript > jQuery' 카테고리의 다른 글
【jQuery/Selector #36】:lang() Selector (0) | 2023.03.05 |
---|---|
【jQuery/Selector #35】:input Selector (0) | 2023.03.05 |
【jQuery/Selector #33】ID Selector (“#id”) (0) | 2023.03.05 |
【jQuery/Selector #32】:hidden Selector (0) | 2023.03.05 |
【jQuery/Selector #31】:header Selector (0) | 2023.03.04 |