You should use siblings instead of closest. Closest will look for the ancestor having the given class. Since the element is the sibling of the clicked element use siblings. $(".cross").click(function() { var status = $(this).parent().attr("class") if (status == 'active') { $(this).parent(this).removeClass("active"); } else { $(this).parent(this).addClass("active"); $(this).siblings("img.icon").fadeOut("fast", function() {}); } });...
It's better I prefer to to hide elements that I'm planning on animating using jQuery itself: http://jsfiddle.net/uv56z6j6/ $(function() { $(".sub-team-description").hide(); $( ".sub-team img" ).click(function() { $(this).siblings("p.sub-team-description").slideToggle("fast"); }); }); I also: added slideToggle(), you may or may not need that, remove it at will removed the emtpy callback, you should...
You just need to figure out which selectors to use. var targetColumns = $(elemClicked).closest("tr").find("td"); this goes up the DOM to the "tr" and selects the tds. If the elemClicked is inside a td you can select the tds with closest("td"), and then use siblings(".draftstatus"); If the elemClicked is a td,...
The heapq.nsmallest() function will do this neatly and efficiently: >>> from heapq import nsmallest >>> s = [1,2,3,4,5,6,7] >>> nsmallest(3, s, key=lambda x: abs(x-6.5)) [6, 7, 5] Essentially this says, "Give me the three input values that have the lowest absolute difference from the number 6.5". The algorithm for nsmallest...
You would need a selector like this: $('.startpoint').closest("li:has(*[data-findme])") That would query for the closest <li> element which contains an element with the attribute data-findme. To grab the anchor from there $('.startpoint').closest("li:has(*[data-findme])").children('[data-findme]') ...
javascript,jquery,append,css-selectors,closest
Check this Demo Fiddle var valueCol = $("table#ruleTable tr td:nth-child(2)"); valueCol.html(function () { return '<input value="' + $(this).text() + '"/>'; }); You can use .append() too, but it would be unnecessary task to append and clear text....
Greedy vs Lazy By default a RegExp quantifier, (+, *, {}). Are greedy. That means they will get as many as they can. Use a ? to make if lazy. Updated: (foo)([\s\S]+?)(doo|some) RegEx101 Alternatives Click on RegExp for Demo (foo)\s*([\S]+?)\s*(doo|some) Will cause white-space to not be selected (foo\s*[\S]+?\s*(?:doo|some)) Will select...
First, attach your event handlers in javascript ... $("button[type='submit']").on('click', transferData); ... then, in the event handler, this is the clicked element (a submit button) : function transferData() { var form_id= this.form.id; ... } ...
I feel taking a risk to answer that but if you try to say theirs absolute value with term closest, you can use Math.Abs method and compare them like; if(Math.Abs(A) > Math.Abs(B)) { // B is closer than A } else if(Math.Abs(B) > Math.Abs(A)) { // A is closer than...
I think you should check your original code again. I've just copied your code and $().next works just fine. var temp2 = $(this).next('select').val(); Fiddle...
Assuming A to be the input 2D matrix, this could be one approach - %// Row and column indices of the "pivot" row_id = 4; col_id = 5; %// Get the linear index from row and column indices lin_idx = sub2ind(size(A),row_id,col_id) %// Logical array with ones at places with same...
Hope the following solve your problem var img = $(".product-info").find('img:first'); ...
javascript,jquery,html5,closest,jquery-find
You can also do something like this quickContent.find("img").click(function() { $(this).closest(".main-wrap").find("ul").slideUp("slow"); // close all other $(this).closest(".column").find("ul").slideDown("slow"); // open current }); ...
With your markup, the simplest is this use of .prev $(function() { $(".dc").on("click",function() { var city = $(this).prev().text(); console.log(city); $("#msg").html("You clicked "+city); }); }); .dc { padding-right:3px;border-right:1px solid black } <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <span class='ccy'>San Diego</span><span class='dc'> X</span> <span class='ccy'>San Francisco</span><span class='dc'> X</span> <span...
javascript,jquery,parent,css-selectors,closest
thisin you code not refer to the current element it refers to the window object. HTML Change onclick="copyOutput()" to onclick="copyOutput(this)" //pass refer of the current element js function copyOutput(el) { //el get current element clicked var output = $(el).closest('tr').find('td:eq(1)').text(); alert(output); } ...
because cont1 is not an ancestor of the button It is the previous sibling of the closest .exp1 element alert($(this).closest(".exp1").prev('.cont1').attr("id")); or you can say, you need the cont1 element within the closest wrapper like(you have a > in the class name wrapper... remove it) alert($(this).closest(".wrapper").children('.cont1').attr("id")); Demo: Fiddle...