jquery-selectors

jQuery - Can't hide parent

吃可爱长大的小学妹 提交于 2019-12-12 12:28:54
问题 I've seemed to stumble upon a problem with a very simple task. I'm trying to hide a parent div when the child is clicked. Here is my HTML; <div class="wave-wrap"><div class="wave">click me</div></div> <div class="wave-wrap"><div class="wave">click me</div></div> <div class="wave-wrap"><div class="wave">click me</div></div> Here is my jQuery; $('.wave').click(function() { alert($(this).parent().html()); $(this).parent().hide('slow'); }); The alert seems to indicate I have the correct selector,

Select second to last element

眉间皱痕 提交于 2019-12-12 12:07:07
问题 i need to select the value of second to last input selectable element: <tr><td><select class="x">...</select></td></tr> <tr><td><select class="x">...</select></td></tr> <tr><td><select class="x">...</select></td></tr> The select input tag are inside tr tags. If I use $("select.x").last() , jQuery select the last element. I need to select second to last. 回答1: You can use .prev() $("select.x").last().prev(); 回答2: You can use .eq() with negative indexes: $("select.x").eq(-2); These negative

jquery selector question: do something only if all elements are hidden

好久不见. 提交于 2019-12-12 11:38:48
问题 I need to do something only if all the li's in a given ul are hidden.. this doesn't seem to do the trick. is there a way? if ($('#some_ul li:hidden')) { // do something only if all 'li's in a given ul are hidden } 回答1: Check the length property of the elements returned. if ( !$('#some_ul li:visible').length ) { // do something only if all 'li's in a given ul are hidden } EDIT: changed hidden to visible EDIT: Clarification on the use of the .length property for a boolean test. Please see

Jquery - How to replace one word in a div?

耗尽温柔 提交于 2019-12-12 11:27:56
问题 I have a div that's copied from another location, and I need to change one word in it. This is the html: <div class="dealer-addy"> 8726 N. Royal Ln<br> Irving, TX 75063<br> email@aol.com </div> I need to change the email address, so I'm trying to get the text inside the div and split the string into words, then change the email address. However, I'm having trouble working with the inner text. This is my script: var address = $dealerInfo.find(".dealer-addy"); var text = $(address).text(); text

error TS2304: cannot find $ in angular 5 component

倾然丶 夕夏残阳落幕 提交于 2019-12-12 11:13:24
问题 I have a side-navbar in angular component which expands on click similar to this. The HTML snippet used to create the navbar is : HTML: As the name( openNav() ) suggests, the following HTML code will expand the navbar : <div> <img (click)="openNav()" src="/imagepath" id="image"> </div> And the following HTML code will close the navbar : <div id="mySidenav" class="sidenav"> <ul class="navbar-nav mr-auto" id="sidenavContent"> <li class="nav-item" id="close-btn"> <img class="closebtn" (click)=

Destroy or recalculate CSS nth-child selector

大兔子大兔子 提交于 2019-12-12 11:11:54
问题 Context : I have a list. Using jQuery, I'm dynamically... ...hiding/showing certain list-items. ...calculating the the third and fourth list-items to apply specific classes. Problem : A CSS style (from a stylesheet), using an nth-child selector, is being applied to every third list item. The problem is that when I dynamically hide/show list items, the CSS nth-child selector doesn't seem to be recalculating. Since jQuery is already calculating the third list item, I don't need to recalculate

How to select first block level parent with jQuery?

元气小坏坏 提交于 2019-12-12 10:50:07
问题 Consider the following markup: <div id="0"> <h1 id="1"> <span id="2"><span id="3">lorem ipsum</span></span> </h1> </div> How can I find the first parent of span#3 that is of block level (i.e. has display: block ) using jQuery? In this case that would be h1#1 . 回答1: $("#3").parents().filter(function() { return $(this).css("display") === "block"; }).first() http://jsfiddle.net/DFURw/ 回答2: Hmm. . . I think that would be $('#3').parents().each(function(){ if ($(this).css('display') == 'block') {

Jquery selector not working on content loaded through ajax

偶尔善良 提交于 2019-12-12 10:18:01
问题 I am having below code to send the value of radio button people have clicked via ajax. But it however only works on the first set of options I give. After the the user press next link and all the options are changed and new one loaeded through ajax. But on that this selector is not working. $(".options input").click(function(){ var ans = $(this).val(); $.post("sessions", { action: "set_answer", answer: ans, question: qid }, function(data) { alert("Data Loaded: " + data); }); }); What is the

How can I select the “shallowest” matching descendant?

江枫思渺然 提交于 2019-12-12 09:38:09
问题 How can I select the first "shallowest" input? My current selection will be the div marked "selected". I won't know how many levels down it will be. <div class="selected"> <!-- already have this --> <div class="unknown-number-of-wrapper-panels"> ... <div class="collection"> <div class="child"> <input type="text" value="2" /> <!-- don't want this --> </div> </div> <input type="text" value="2" /> <!-- need this --> <input type="text" value="2" /> ... </div> </div> It seems like find().first()

How to find <script> elements with particular value of “type” attribute?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-12 08:28:03
问题 Assuming the following script tag in a random HTML document: <script id="target" type="store"> //random JavaScript code function foo(){ alert("foo"); } foo(); </script> can anybody explain why the following expression doesn't find all elements of script with value store for their type attribute. var sel = $('#target script[type="store"]'); jQuery version: v1.7.2 Chrome version: 25.0.1364.172 (running on Debian Squeeze) 回答1: Your selector $('#target script[type="store"]') would match any