jquery-selectors

jQuery’s .bind() vs. .on()

爱⌒轻易说出口 提交于 2019-12-16 23:49:42
问题 I found two great articles talking about the new function .on() : jquery4u.com, elijahmanor.com. Is there any way where the .bind() still is better to use than .on() ? For example, I have a sample code that look like this: $("#container").click( function( e ) {} ) You can note that I just have one item retrieved by the selector and in my case, the <div> named #container already exists when my page was loaded; not added dynamically. It’s important to mention that I use the latest version of

jQuery selectors on custom data attributes using HTML5

和自甴很熟 提交于 2019-12-16 22:34:11
问题 I would like to know what selectors are available for these data attributes that come with HTML5. Taking this piece of HTML as an example: <ul data-group="Companies"> <li data-company="Microsoft"></li> <li data-company="Google"></li> <li data-company ="Facebook"></li> </ul> Are there selectors to get: All elements with data-company="Microsoft" below "Companies" All elements with data-company!="Microsoft" below "Companies" In other cases is it possible to use other selectors like "contains,

jQuery to loop through elements with the same class

南楼画角 提交于 2019-12-16 22:21:12
问题 I have a load of divs with the class testimonial and I want to use jquery to loop through them to check for each div if a specific condition is true. If it is true, it should perform an action. Does anyone know how I would do this? 回答1: Use each: ' i ' is the postion in the array, obj is the DOM object that you are iterating (can be accessed through the jQuery wrapper $(this) as well). $('.testimonial').each(function(i, obj) { //test }); Check the api reference for more information. 回答2: try

Why is my jQuery :not() selector not working in CSS?

泄露秘密 提交于 2019-12-16 19:30:45
问题 I have this layout: <div id="sectors"> <h1>Sectors</h1> <div id="s7-1103" class="alpha"></div> <div id="s8-1104" class="alpha"></div> <div id="s1-7605" class="beta"></div> <div id="s0-7479"></div> <div id="s2-6528" class="gamma"></div> <div id="s0-4444"></div> </div> With these CSS rules: #sectors { width: 584px; background-color: #ffd; margin: 1.5em; border: 4px dashed #000; padding: 16px; overflow: auto; } #sectors > h1 { font-size: 2em; font-weight: bold; text-align: center; } #sectors >

Why is my jQuery :not() selector not working in CSS?

最后都变了- 提交于 2019-12-16 19:28:07
问题 I have this layout: <div id="sectors"> <h1>Sectors</h1> <div id="s7-1103" class="alpha"></div> <div id="s8-1104" class="alpha"></div> <div id="s1-7605" class="beta"></div> <div id="s0-7479"></div> <div id="s2-6528" class="gamma"></div> <div id="s0-4444"></div> </div> With these CSS rules: #sectors { width: 584px; background-color: #ffd; margin: 1.5em; border: 4px dashed #000; padding: 16px; overflow: auto; } #sectors > h1 { font-size: 2em; font-weight: bold; text-align: center; } #sectors >

How to get the list of items that have a particular subitem?

邮差的信 提交于 2019-12-14 04:22:13
问题 I have table where each row starts with a "checkbox", I'd like to get all the TR that contains a checkbox and it is check. Something like this: $('#' + tableId + ' > tbody > tr:contains(td > input[type=checkbox]:checked').each(function (i, item) { alert('delete ' + $(item).data('row-id')); }); That code doesn't work, it gets stuck. Probably because the "contains" selector is only for text. How could I do it? Regards. 回答1: Use jQuery's has: $('#' + tableId + ' > tbody > tr:has(td > input[type

How can I change nested table td border width using jQuery?

不羁的心 提交于 2019-12-14 04:18:45
问题 HTML <hr /> <h1>Table-1</h1> <hr /> <table class="tb1"> <tr> <td>rw1</td> <td>rw1</td> <td>rw1</td> </tr> <tr> <td>rw1</td> <td>rw1</td> <td>rw1</td> </tr> <tr> <td colspan="3"> <table class="tb2"> <tr> <td>tbrw2</td> <td>tbrw2</td> <td>tbrw2</td> </tr> <tr> <td>tbrw2</td> <td>tbrw2</td> <td>tbrw2</td> </tr> </table> </td> </tr> <tr> <td>rw1</td> <td>rw1</td> <td>rw1</td> </tr> <tr> <td colspan="3"> <table class="tb2"> <tr> <td>tbrw2</td> <td>tbrw2</td> <td>tbrw2</td> </tr> <tr> <td>tbrw2</td

Replace Name Attribute with Variable - JQUERY

非 Y 不嫁゛ 提交于 2019-12-14 03:58:34
问题 I am using a select element to change the search type on a media site (i.e. search by genre, search by artist). I have created the dropdown and can get the selected option via a variable but now I need to replace the name attribute on the input element with the variable/selected option. I have seen the below code to change the "value", is there anything like this for changing the name attribute on an input element. $("input[name$='letter']").val("a letter"); 回答1: .attr('name', 'blah') 来源:

Display array values as unique tooltip in highcharts

馋奶兔 提交于 2019-12-13 23:15:32
问题 I am trying to display values of an array as tooltip in highcharts line graph.I am currently using values entered from a textbox as tooltip but trying to display array values as tooltip..the js fiddle is given here http://jsfiddle.net/RbenU/75/ the tooltip code i am using is.. tooltip: { formatter: function () { var serieI = this.series.index; var index = categories.indexOf(this.x); var comment = $("input:eq(" + (index) + ")").val(); return '-->'+comment; } }, I want to display values of

exclude value from one select box based on value of other selectbox

梦想与她 提交于 2019-12-13 20:18:16
问题 I am trying to exclude from one select list what the user has chosen in the other select list. It is a list of 2 questions and the user can not select the same question in both select lists For some reason it works for the first couple of selections but then it start altering the value of the second box to a value it was not. It works fine for a couple of selections on both but if you keep selecting between the 2 it start to return incorrect results Below is the jquery code but here is the