mirror of
https://github.com/Hopiu/jquery-mobile.git
synced 2026-03-18 06:50:23 +00:00
61 lines
No EOL
2.6 KiB
HTML
61 lines
No EOL
2.6 KiB
HTML
<!DOCTYPE html>
|
|
<html lang='en'><head><meta http-equiv='content-type' content='text/html; charset=UTF-8' /></head><body>
|
|
<div class="ui-page">
|
|
<div class="ui-header">
|
|
<h1>.hasClass()</h1>
|
|
|
|
</div>
|
|
<div class="ui-content ui-body ui-body-c" id="hasClass1">
|
|
<h2 class="jq-clearfix roundTop section-title">
|
|
<span class="name">.hasClass( className )</span> <span class="returns">Returns: <a class="return" href="http://docs.jquery.com/Types#Boolean">Boolean</a></span>
|
|
</h2>
|
|
<div class=" entry-details">
|
|
<p class="desc"><strong>Description: </strong>Determine whether any of the matched elements are assigned the given class.</p>
|
|
<ul class="signatures"><li class="signature" id="hasClass-className">
|
|
<h4 class="name">
|
|
<span class="versionAdded">version added: <a href="/category/version/1.2/">1.2</a></span>.hasClass( className )</h4>
|
|
<p class="arguement"><strong>className</strong>The class name to search for.</p>
|
|
</li></ul>
|
|
<div class="longdesc">
|
|
<p>Elements may have more than one class assigned to them. In HTML, this is represented by separating the class names with a space:</p>
|
|
<pre><div id="mydiv" class="foo bar"></div></pre>
|
|
<p>The <code>.hasClass()</code> method will return <code>true</code> if the class is assigned to an element, even if other classes also are. For example, given the HTML above, the following will return <code>true</code>:</p>
|
|
<pre>$('#mydiv').hasClass('foo')</pre>
|
|
<p>as would:</p>
|
|
<pre>$('#mydiv').hasClass('bar')</pre>
|
|
</div>
|
|
<h3>Example:</h3>
|
|
<div id="entry-examples" class="entry-examples"><div id="example-0">
|
|
<h4><span class="desc">Looks for the class 'selected' on the matched elements.</span></h4>
|
|
<pre><code class="example demo-code"><!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<style>
|
|
|
|
p { margin: 8px; font-size:16px; }
|
|
.selected { color:red; }
|
|
.highlight { background:yellow; }
|
|
</style>
|
|
<script src="http://code.jquery.com/jquery-latest.js"></script>
|
|
</head>
|
|
<body>
|
|
<p>Hello</p>
|
|
<p class="selected">Goodbye</p>
|
|
<div id="result1">First paragraph has selected class: </div>
|
|
|
|
<div id="result2">Last paragraph has selected class: </div>
|
|
<div id="result3">Some paragraph has selected class: </div>
|
|
<script>$("div#result1").append($("p:first").hasClass("selected").toString());
|
|
$("div#result2").append($("p:last").hasClass("selected").toString());
|
|
$("div#result3").append($("p").hasClass("selected").toString());</script>
|
|
</body>
|
|
</html></code></pre>
|
|
<h4>Demo:</h4>
|
|
<div class="demo code-demo"></div>
|
|
</div></div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</body></html> |