jquery-selectors

Click a specific submit button with JQuery

人盡茶涼 提交于 2019-12-20 11:13:51
问题 I am clicking a submit button using this: $('input[type=submit]').click(); The problem is that I have more that 1 submit button on my page so I need to target a specific submit button. How could I do that? 回答1: If you know the number of submit inputs and which one (in order) you want to trigger a click on then you can use nth-child() syntax to target it. Or add an ID or a class to each one that separates them from the other. Selecting the elements by their index: $('input[type="submit"]:nth

jQuery - Multiple Selectors in a :not()?

情到浓时终转凉″ 提交于 2019-12-20 10:16:05
问题 I cant seem to get the following working: $('input:not([type=radio][type=checkbox])').live('click', function() { alert("You haven't clicked a radio or checkbox!"); }); Have tried a few different syntax's, can anyone help me out on this one. Cheers Charlie 回答1: You're confusing the multiple selector with the multiple attribute selector. You should write: $("input:not([type=radio], [type=checkbox])"); The multiple attribute selector [type=radio][type=checkbox] matches the elements whose type

jQuery $(element).each function doesn't work on newly added elements

蹲街弑〆低调 提交于 2019-12-20 09:37:28
问题 I am using .each function to iterate trough list of elements. I am having initial list of matched elements and .each works great on these. But I can add new elements via AJAX method... .each don't work on this newly added elements? I know about live events and rebinding of events for newly added elements, but .each is not event I could not find any help on how to use this correctly to affect newly added elements. How to solve this? //Uploadify callback where I add new items onComplete:

jQuery delete all table rows except first

女生的网名这么多〃 提交于 2019-12-20 07:56:56
问题 Using jQuery, how do I delete all rows in a table except the first? This is my first attempt at using index selectors. If I understand the examples correctly, the following should work: $(some table selector).remove("tr:gt(0)"); which I would read as "Wrap some table in a jQuery object, then remove all 'tr' elements (rows) where the element index of such rows is greater than zero". In reality, it executes without generating an error, but doesn't remove any rows from the table. What am I

How to get the closest element id attribute

非 Y 不嫁゛ 提交于 2019-12-20 07:10:30
问题 I am trying to find the closest element that has id attribute and get the id . The element could be <p>, <div> or other elements. I have tried element=$('#test').closest('div[id]').attr('id'); but it only get the id if the element is a div . I want to be more universal. Are there anyways to do this? Thanks so much! 回答1: You can get rid of the div entirely and look for all elements that have an id attribute: $('#test').closest('[id]').attr('id'); 来源: https://stackoverflow.com/questions

Get Text Select That Runat=“Server”

橙三吉。 提交于 2019-12-20 06:15:09
问题 <select id="Select1"> <option>1</option> <option>2</option> <option>3</option> </select> alert($("#Select1").val()); this code Is Correct And Return Current Value. BUT <select runat="server" id="Select1"> <option></option> </select> function parseXmlQuestion(xml) { $(xml).find("Question").each(function() { var value=$(this).find('Text').text() $('#<%=Select1.ClientID %>'). append($("<option></option>"). attr("value",value). text(value)); }); } alert( $('#<%=Select1.ClientID %>').val()); alert

jQuery selector what's difference between jQuery(“element”) and $(“element”)?

狂风中的少年 提交于 2019-12-20 04:31:23
问题 I used jQuery many times ago, but always used like this: $(document) . Lately i seen many times somebody using jQuery(document) , I don't know difference between them, I thought they are same. But I have very hard problem now. You know most of jQuery plugin uses $(document) method. Now I have one must use plugin that uses jQuery(document) . I must include that, but after included I can't no longer use $(document) method and plugins which uses it. How can I solve it? 回答1: $ is just a short

Resize div in jquery from right to left

早过忘川 提交于 2019-12-20 03:44:04
问题 I want to animate and resize div tag from right to left . By default i have learnt from examples and found it resizes from left to right but as per project requirement we wish to have it in right to left order. The code I have written is : <script type="text/javascript"> $(document).ready(function() { $("button").click(function() { $("div#div1").animate({height:166},5000); $("div#div1").animate({width:800},5000); }); }); </script> <div id="div1" style="background:url(stripes.JPG);height:0px

Selecting a variable's nested elements - jQuery

雨燕双飞 提交于 2019-12-20 03:38:11
问题 I wish to pass a variable to a function and have the function select elements within that variable. I'm unfamiliar with the syntax of this case however, could any one advise? For example, when a button is clicked within a container I wish for that container to be stored in a variable, okay I have that part. But then I wish to select a certain element within that container like $(container "div#element"); How can you combine the two, noting that these elements could be deeply nested? 回答1:

jQuery combine multiple elements

北城以北 提交于 2019-12-20 03:29:09
问题 I was experimenting with jQuery and came across a question. Can I use an actual selector with existing element as a combined selector for jQuery? So, suppose I've created a DIV element on-the-fly: var $div = $('<div>') .css('position', 'absolute') .hide(); // Just to be short $('body').append($div); And I want to show it when user hovers over P elements / paragraphs (at the cursor position): $('p').hover(function(e) { // Change the position of $div with regards of cursor position $div.show();