jquery-selectors

Performance of jquery selectors vs css3 selectors

元气小坏坏 提交于 2020-01-02 05:26:45
问题 I am fairly new to css3 using selectors (or simple css selectors in general) and am curious about the performance comparison of these css selectors vs jquery or javascript selectors? Say you have something like this: css version #someID > div:nth-child(2n) { some css .... } jquery version (edit) $("#someID").children(":nth-child(even)").css({ some css ....}); Is it often faster to use the css selectors whenever you can, or use jquery selectors to adjust the css involved with an element or set

how to add an element always as last element using jquery?

半腔热情 提交于 2020-01-02 02:31:07
问题 I want a certain div to be added as the last element in a list no matter what. Is there any way in which I can explicitly specify this? 回答1: Get the parent of the list and add the new item to that parent as the last child. Using plain javascript: parent.appendChild(newElement); Mozilla documentation: https://developer.mozilla.org/En/DOM/Node.appendChild If you want to add other items and still have this item be the last item, then you will have to add the new items before this last item or

jQuery: select all inputs with unique id (Regex/Wildcard Selectors)

江枫思渺然 提交于 2020-01-02 01:21:11
问题 I have some textboxes on a webform that have ids like this: txtFinalDeadline_1 txtFinalDeadline_2 txtFinalDeadline_3 txtFinalDeadline_4 In my jQuery how do I find all of those in order to assign a value to them. Before I had the underscore and they were all named txtFinalDeadline I could do this and it worked. $(this).find("#txtFinalDeadline").val(formatDate); However, that was when they were all named the same thing. Now I have the _x after the name and I'm not sure how to go about assigning

Jquery detect change or keyup on body tag within iframe

与世无争的帅哥 提交于 2020-01-01 10:07:15
问题 I have a jwysiwyg content editor control on my page. The control works by creating itself in an iframe which has a full html page code within it. I wish to detect if there has been a change or keyup so I can use our "indicate the record needs to be saved" code. We have input boxes and this work fine, just this 3rd party editor control is giving us problems. Here is what the page source looks like: <div id="this_is_our_div_Container"> <div class="wysiwyg"> <iframe id="f_Body-wysiwyg-iframe">

Jquery detect change or keyup on body tag within iframe

有些话、适合烂在心里 提交于 2020-01-01 10:06:25
问题 I have a jwysiwyg content editor control on my page. The control works by creating itself in an iframe which has a full html page code within it. I wish to detect if there has been a change or keyup so I can use our "indicate the record needs to be saved" code. We have input boxes and this work fine, just this 3rd party editor control is giving us problems. Here is what the page source looks like: <div id="this_is_our_div_Container"> <div class="wysiwyg"> <iframe id="f_Body-wysiwyg-iframe">

Using JQuery to change order of elements

你。 提交于 2020-01-01 03:15:11
问题 Does anybody know what I'm doing wrong? I'm trying to alter the order on which some images show, I want the images to shift to the right/left one spot every time I hit a button. This is what I've tried but no luck. Any help or insight will be truly appreciated $("#rightShift").click(function(){ $("img").hide(); var count = $("img").size(); $("img").each(function(i) { var indexImg = count - i; $("img:eq(indexImg)").show(); }); }); $("#leftShift").click(function(){ $("img").hide(); $("img:last"

Count li elements that are visible with jQuery

泄露秘密 提交于 2020-01-01 02:48:12
问题 Im counting my li elements with the following jQuery script: HTML: <ul class="relatedelements"> <li style="display:none;" class="1">anything</li> <li style="display:none;" class="2">anything</li> <li style="display:none;" class="3">anything</li> </ul> jQuery: $(function() { var numrelated=$('.relatedelements > li').length; $('.num-relatedelements').html(numrelated); }); --> The script returns: 3 I change the style="display: none" property of some of the li elements when $(document).ready with

Select all inputs of a given form in Jquery

房东的猫 提交于 2019-12-31 07:07:30
问题 I have a form object in jquery, and I'd like to select all inputs of this form. Let's suppose my form object is called form . If the form has an id, I can just do var id = form.attr('id'); var inputs = $('#' + id + ' input'); If not I can check this, and then manually add a temporary id, do the selection, and remove the id (or just leave it there). But this just looks too complicated, there must be an easier way, but I'm not able to find it. Another possible way (which I'm not able to make

.not() with .live() not working

做~自己de王妃 提交于 2019-12-31 04:56:07
问题 jQuery("a").not("div#mnuMain a").live("click", function(event){ event.preventDefault(); alert("yes I got u"); }); How to make it work? 回答1: Try putting it all in the main selector: Example: http://jsfiddle.net/8Tkex/ jQuery("a:not(div#mnuMain a)").live("click", function(event){ event.preventDefault(); alert("yes I got u"); }); EDIT: The reason using .not() didn't work is that when you use jQuery's live() method, you're not actually placing the click handler on the element. Instead you're

addClass causing undefined is not a function

坚强是说给别人听的谎言 提交于 2019-12-31 04:17:30
问题 I have: mouseOver: function () { var catId = this.category_id; $('#expenditureSummaryGrid .k-grid-content tr').each(function() { if($('td span', this).data('id') == catId) { this.addClass('grid-hover'); } }) }, But it's giving me: Uncaught TypeError: undefined is not a function Which isn't making much sense since "this" is the expected DOM element I'm trying to add a class too. What is going wrong? 回答1: Since .addClass() is a jQuery function, you likely need to change this.addClass('grid