- Dom
- click
- inArray
- merge objects
- query string
- smartcheck
- attr
- addClass
- hasClass
- removeClass
- append
- prepend
- remove
- has
- findAll
- empty
- position
- offset
- outerWidth
- outerHeight
- replaceWith
- html
- text
- val
- parseHTML
- parseJSON
- parent
- next
- prev
- first
- last
- now
- toArray
- size
- Manipulation
- dates compare
- getMonthName
- getDayName
- .NET JSON date
- hashtag
- number Format
- pad
- smallCase
- upperCase
- Forms
- focus
- mobile number
- repetition
- placeholder
- Browser
- browser feature
- Browser Information
- Effects
- hide
- show
- sticky
- scrolline
- goUp
- Animation
- circles
- Google analytics
- Google fonts
.prev()
Description: Get the previous element that's before the first matched element.
Example:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>prev demo</title>
<script src="http://code.bitsycode.com/bitsycode-latest.min.js"></script>
<style type="text/css">
.active {
background-color:yellow;
}
</style>
</head>
<body>
<ul class="myList">
<li>One</li>
<li>Two</li>
<li class="active">Three</li>
</ul>
<button onclick="prev()">Prev</button>
<script>
function prev() {
if ((bitsyCode(".active").prev()).nodes.length > 0) {
bitsyCode(".active").removeClass("active").prev().addClass("active");
} else {
bitsyCode(".myList").first().removeClass("active");
bitsyCode(".myList").last().addClass("active");
}
}
</script>
</body>
</html>
Preview:
- One
- Two
- Three
Share