logo
down
shadow

Find the element before the previous element - jQuery


Find the element before the previous element - jQuery

By : Ahmad Khaskieh
Date : November 22 2020, 01:01 AM
around this issue If your "this current element" changes, some code like the following might be useful:
I used a different example: http://jsfiddle.net/swm53ran/5/ to illustrate the ability of $(this) with the .prev().prev() that may be helpful for your problem.
code :
$(this).prev().prev().css('color', 'red');


Share : facebook icon twitter icon
ancestor Get previous sibling Get the children
How to find the previous element of the specified element in jquery

How to find the previous element of the specified element in jquery


By : Tim Lee
Date : March 29 2020, 07:55 AM
Does that help .prev() will only match the immediately preceding element, and if you've supplied a selector, only if it matches that selector.
Given the existing HTML snippet you need:
code :
$('#findbefore').prev().find('.SharedImage');
$(this).closest('.SPcommentbox').prev().find('.SharedImage');
$('#SharedImage')
How to find the previous <div> element from a <div>? using jquery?

How to find the previous <div> element from a <div>? using jquery?


By : Md Ali
Date : March 29 2020, 07:55 AM
Does that help Here is my code: , This will help you
code :
$('divId').prev('div').find('span').attr('class')
How to find previous td element using jquery

How to find previous td element using jquery


By : Hetvi
Date : March 29 2020, 07:55 AM
it should still fix some issue As there is no sibling(
) before the element #space_bet3, prev() on it will return empty set.
Get the
Get the id attribute value.
code :
$('#space_bet3')
    .closest('tr') // Get first ancestor `<tr>` element
    .prev() // Get previous element
    .children('td') // Get direct descendant `<td>` element
    .attr('id'); // Get `id` of the element
var id = $('#space_bet3')
  .closest('tr') // Get first ancestor `<tr>` element
  .prev() // Get previous element
  .children('td') // Get direct descendant `<td>` element
  .attr('id'); // Get `id` of the element

console.log(id);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<table>
  <tr>
    <td id="space_bet1" height="10"></td>
  </tr>
  <tr>
    <td id="unscr1">Today</td>
  </tr>
  <tr>
    <td id="space_bet2" height="10"></td>
  </tr>
  <tr>
    <td id="unscr2">Tomorrow</td>
  </tr>
  <tr>
    <td id="space_bet3" height="10"></td>
  </tr>
  <tr>
    <td id="unscr3">Yesterday</td>
  </tr>
  <tr>
    <td id="space_bet4" height="10"></td>
  </tr>
  <tr>
    <td id="unscr4">next week</td>
  </tr>
  <tr>
    <td id="space_bet5" height="10"></td>
  </tr>
  <tr>
    <td id="unscr5">next month</td>
  </tr>
  <tr>
    <td id="space_bet6" height="10"></td>
  </tr>
</table>
Find previous DOM element jquery using this

Find previous DOM element jquery using this


By : yaraa wee
Date : March 29 2020, 07:55 AM
around this issue You already inside the current .box that you hover when you use jQuery(this).
You need to remove the .box and to use prev right after the jQuery(this)
code :
jQuery(".box").hover(
    function() {
        jQuery(this).find(".box-content").css( "border-right", "none" );
        jQuery(this).prev().find(".box-content").css( "border-right", "none" );
    },
    function() {
        jQuery(this).find( ".box-content" ).css( "border-right", "1px solid black" );
        jQuery(this).prev().find(".box-content").css( "border-right", "1px solid black" );
    }
);
Jquery : find previous element from element with specific class on lists

Jquery : find previous element from element with specific class on lists


By : Ravisinh Mori
Date : March 29 2020, 07:55 AM
seems to work fine You can use :has() selector to get
  • having a.pagination.current element then use .prev() to get its immediately preceding sibling
    code :
    var prevli = $("#pagin li:has(a.pagination.current)").prev();
    var prevLiAnchor = prevli.find('a');
    
    $("#pagin li:has(a.pagination.current)").prev().css('color', 'red')
    .current{ color : green}
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <ul id="pagin">
      <li><a id="previous">&lt;</a></li>
      <li><a class="pagination">1</a></li>
      <li><a class="pagination">2</a></li> 
      <li><a class="pagination current">3</a></li>
    </ul>
  • Related Posts Related Posts :
  • angular 6 Please add a @NgModule annotation
  • Trying to cast element ID to class selector in jQuery
  • Swipe JS - Display 3 Slides at a time
  • Jasmine test to call function when value is null
  • Redux reducer gets string instead of object
  • Keep chrome javascript running even if page reload
  • The event.target.value is not insert the userinput into a variable
  • Exporting HTML tables to Excel (.xls) in a separate sheet
  • Jquery tooltip on dialog close button
  • access variable inside anonymous function from outside
  • How come func is called from a function?
  • How to change add and remove active class in JavaScript
  • how to toggle a specific div in javascript
  • How to get all the values from multiple keys of an array of object?
  • jQuery bind() unbind() and on() and off()
  • regular expression to find DD Month YYYY from a string
  • How to upload files from web client (HTML/jQuery form) to your Dropbox folder
  • Backbone history and require.js issue
  • Confusion over Classical and Prototypal Inheritance Javascript
  • How to take screen shot of current webpage using Javascript/JQuery?
  • Store meridiem in a variable
  • class declared inside closure vs standard class without closure
  • javascript confirm box always return true
  • dynamically changing the size of font size based on text length using css and html
  • Node.js - Getting the host IP address while on Amazon EC2
  • Confusing CSS, can anyone explain please
  • How to install v8-profiler on Windows 8 (64 bit) using npm?
  • Resolve promise based on another promise
  • google maps adding overlay layer above UI and markers
  • Style specific letter?
  • RangeError: Maximum call stack size exceeded with array.slice
  • node rest client get with local variable
  • If condition not executes while mouse move fastly
  • Count the number of displayed elements in a HTML list
  • Locate JavaScript source code in Emacs
  • Clean, Modular Code vs MV* Frameworks
  • infinite scroll without loading image
  • Backbone: reverse collection order with comparator
  • What do printers ignore?
  • jQuery UI .tabs() Contentless tab?
  • Execute Javascript alert() after page (visually) loaded
  • JavaScript - duplicating array doesn't work
  • Excessive clickable area below image
  • JavaScript Regex: Replace |b| with <b>
  • Unexpected value change in 2D array in JavaScript
  • Function doesnt see parameter as a array of objects
  • jQuery fetch keypress event on chrome and IE
  • How to enable jquery validate localization?
  • Cassandra map collection returned by node.js Helenus looks odd
  • angular ng-repeat with multiple filter options
  • Selecting Children without ID or Class names
  • How to uncheck a group of checkboxes when another checkbox is checked
  • Is hiding content by Javascript or jQuery Worth trying
  • Load XUL resource using javascript
  • XML to HTML text area from server file system
  • set focus() on textbox on form onload
  • es lint '' is assigned a value but never used' eventhough i have used it
  • Can "name" attribute be used for custom VueJS components
  • Get innerHTML of content when it is clicked
  • HTTPS causes CSS animations to not load? Very confused
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org