jquery-selectors

jQuery selector to get form by name

坚强是说给别人听的谎言 提交于 2019-12-18 12:47:14
问题 I have the following HTML: <form name="frmSave">...</form> Just to know, I am not able to modify the HTML in order to add an id or something else. This is what I tried to get the form element by it's name: var frm = $('form[name="frmSave"]'); console.log(frm); (but I believe the above code will try to get a children element with the frmSave name inside the form which is not what I need). How can I achieve this, is it possible to get the form by just the name and using a selector? Update: I

jQuery replace text leaving siblings intact

坚强是说给别人听的谎言 提交于 2019-12-18 11:53:20
问题 I'm having trouble wrapping my head around what should be a simple solution. I want to replace text within a label tag, without affecting the other 'siblings', if they exist. Sample markup: <fieldset class="myFieldsetClass"> <legend>Sample Fieldset</legend> <ol> <li> <label> <span class="marker">*</span> Some Label 1 </label> </li> <li> <label> Some Label 2 </label> </li> <li> <label> Text that doesn't match... </label> </li> </ol> </fieldset> Goal: To replace text Some Label X with Some

jQuery: How to select “from here until the next H2”?

限于喜欢 提交于 2019-12-18 11:02:30
问题 I'm setting up a very straightforward FAQ page with jQuery. Like so: <h2>What happens when you click on this question?</h2> <p>This answer will appear!</p> This is all inside a very specific div, so I'll be selecting the header with $('#faq h2') . Simple, right? Click on the H2, and use this.next() to make the next paragraph show up. (The caveat with this page is that a non-programmer will be maintaining it, which is why I'm not using classes: there's no guarantee that any new entries would

jQuery: How to select “from here until the next H2”?

随声附和 提交于 2019-12-18 11:02:03
问题 I'm setting up a very straightforward FAQ page with jQuery. Like so: <h2>What happens when you click on this question?</h2> <p>This answer will appear!</p> This is all inside a very specific div, so I'll be selecting the header with $('#faq h2') . Simple, right? Click on the H2, and use this.next() to make the next paragraph show up. (The caveat with this page is that a non-programmer will be maintaining it, which is why I'm not using classes: there's no guarantee that any new entries would

jQuery - Click event on <tr> elements with in a table and getting <td> element values

混江龙づ霸主 提交于 2019-12-18 11:00:51
问题 I have the following HTML in a JSP file: <div class="custList"> <table class="dataGrid"> <c:forEach var="cust" items="${custList}"> <tr> <td>${cust.number}</td> <td>${cust.description}</td> <td>${cust.type}</td> <td>${cust.status}</td> </tr> </c:forEach> </table> </div> I need to be able to trigger a 'click' event on each of the dynamically created <tr> tags and also be able to access the values of the <td> tags (of the clicked <tr> ) from within the JavaScript function. I have this function

Most appropriate way to get this: $($(“.answer”)[0])

℡╲_俬逩灬. 提交于 2019-12-18 10:48:23
问题 Suppose I want to get the first element amongst all the elements of the class ".answer" $($(".answer")[0]) I can do the above, but what is the best balance between elegance and speed? *changed the question to reflect the current discussion 回答1: The following are all equivalent in functionality (though not speed): var a0 = $($('.answer')[0]); var a0 = $('.answer').first(); - see http://api.jquery.com/first/ var a0 = $('.answer:first'); - see http://api.jquery.com/first-selector/ var a0 = $('

jQuery select ancestor

雨燕双飞 提交于 2019-12-18 10:40:56
问题 Is is possible to use jQuery to select an ancestor of an element? Markup: <div id="ancestor-1"> <div> <a href="#" class="click-me">Click me</a> </div> </div> <div id="ancestor-2"> <div> <a href="#" class="click-me">Click me</a> </div> </div> Script: $(".click-me").click(function(){ // var ancestorId = ???; alert(ancestorId) }); 回答1: Try parent() for the immediate parent element. $(".click-me").click(function() { var ancestor = $(this).parent(); alert(ancestor) }); Or parents() for all

jQuery - Getting the text value of a table cell in the same row as a clicked element

浪子不回头ぞ 提交于 2019-12-18 10:27:12
问题 I click a link in a table cell. I need to get the value of a specific cell within this same table row. <tr> <td class="one">this</td> <td class="two">that</td> <td class="three">here</td> <td class="four"><a href="#">there</a></td> </tr> <tr> <td class="one">qwqw</td> <td class="two">dfgh</td> <td class="three">ui</td> <td class="four"><a href="#">there</a></td> </tr> I have a click handler attached to the link in the fourth cell. That click handler calls a function that opens a modal window.

jQuery - Getting the text value of a table cell in the same row as a clicked element

被刻印的时光 ゝ 提交于 2019-12-18 10:27:04
问题 I click a link in a table cell. I need to get the value of a specific cell within this same table row. <tr> <td class="one">this</td> <td class="two">that</td> <td class="three">here</td> <td class="four"><a href="#">there</a></td> </tr> <tr> <td class="one">qwqw</td> <td class="two">dfgh</td> <td class="three">ui</td> <td class="four"><a href="#">there</a></td> </tr> I have a click handler attached to the link in the fourth cell. That click handler calls a function that opens a modal window.

jquery - get all rows except the first and last

落花浮王杯 提交于 2019-12-18 10:22:27
问题 i want to dynamically add a class to all rows of a table except the first and last row. how would i do this without assigning a css class to the rows to identify them. I am getting all but the first row currently with $("#id").find("tr:gt(0)") i need to combine this with not("tr:last") somehow maybe? 回答1: Drop the gt() , as I'd assume it's a tiny bit slower than :first . Use not() in conjunction with :first and :last : $('table#tbl > tbody > tr').not(':first').not(':last').addClass('highlight