jquery-selectors

hide/show a image in jquery

混江龙づ霸主 提交于 2019-12-12 07:49:10
问题 How to show/hide the image on clicking the hyperlink? <script> function getresource(id) { if(id==4) { //show image } else if(id==5) { //hide image } } </script> <a href="#" onclick="javascript:getresource('4');">Bandwidth</a> <a href="#" onclick="javascript:getresource('5');">Upload</a> <p align="center"> <img id="img3" src="/media/img/close.png" style="visibility: hidden;" /> <img id="img4" src="/media/img/close.png" style="visibility: hidden;" /> </p> 回答1: What image do you want to hide?

How to delete the first child of an element but referenced by $(this) in Jquery?

南笙酒味 提交于 2019-12-12 07:46:32
问题 The scenario is I have two div s: one is where I select items ( divResults ) and it goes to the next div ( divSelectedContacts ). When I select it I place a tick mark next to it. What I want to do is when I select it again I want to remove the tick mark and also remove the element from divSelectedContacts . Here is the code: $("#divResults li").click(function() { if ($(this).find('span').size() == 1) { var copyElement = $(this).children().clone(); $(this).children().prepend("<span class='ui

Difference of $(document) and $('parentSelector') for adding events of dynamically add element?

佐手、 提交于 2019-12-12 06:07:34
问题 I am confused with the $(document) in using this as my selector for a click event ? Any difference or cos instead of using only the parent selector? Both of them produces the same output but is there any factor like executing speed? You can test this FIDDLE var counter = 0; Using parent selector $(".parent").on("click", "button.btn", function(){ $(".parent").append("<button class = 'btn'> new button " + (++counter) + "</button><br />"); }); or $(document) $(document).on("click","button.btn"

This but not $(this)

落爺英雄遲暮 提交于 2019-12-12 05:52:33
问题 OK so in jQuery; I have a selecter $("#gmap") I want to do alot of code in context of my selector. I have always been lazy and used .each() even though there is only one of them. $("#gmap321654987789").each(function(){ $(this)..... }); Is this particuarly effitiant? I hate code that doesn't feel 'right'. Is there a mechanism for say... or something similar. $("#gmap321654987789").this(function(){ $(this)..... }); 回答1: Just cache the object and work with it like normal: var $gmap = $('

How to wrap multiple div blocks with different class names in jQuery? [duplicate]

烈酒焚心 提交于 2019-12-12 05:25:57
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: How to wrap DIV tags with different class names in jQuery? I have the following HTML blocks repeated in the document <!-- first block --> <div class="first"> My first div </div> <div class="second"> My second div </div> <!-- second block --> <div class="first"> My first div </div> <div class="second"> My second div </div> ... How can I wrap the blocks of Divs with jQuery to get the following result... <!-- first

Select multidimensional arrays from form with jquery

拈花ヽ惹草 提交于 2019-12-12 05:11:17
问题 I tried to select a multidimensional form item with JQuery. But when I try to alert its value I just get an undefined . This is my form: <select name='item[1][name]'> <option value='1'>Name 1</option> <option value='2'>Name 2</option> <option value='3'>Name 3</option> <option value='4'>Name 4</option> </select> <input type='text' name='item[1][id]' class='text' /> When I click on submit button, I try to select all my form elements. I successfully selected the text input field with: var item1i

jQuery function for specific class

假如想象 提交于 2019-12-12 05:05:30
问题 I am running a custom loop in a wordpress page that should list all the shoes in one category as well as the color selectors. I got the loop running just fine, and page looks ok. But I have a big problem with jQuery script that changes the images. Each post has: Several images of different colored shoes and selectors for colors - different shoes have a different number of colors (you can see a demo at: http://www.etfovac.com/testbed/shoe/ - the final page should look like this http://www

Trying to set css property LEFT to using Jquery - Centering image inside DIV

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 05:00:01
问题 This code is supposed to reposition gallery images inside of their square div boxes. All the images have a set height e.g. 100px. But their widths are different. Rather than only show the left-most 100px of every picture, I'd rather it show the center. All I need is to go through each img and change the left property to shift the images left. $('img.gall_imgs').load(function() { var $imgWidth = parseInt($(this).width); // "$(this)" or "this"? parseInt() needed? var $divWidth = parseInt($(this

jQuery select class with a number. e.g. foo1, foo2, foo3, foo4

牧云@^-^@ 提交于 2019-12-12 04:04:23
问题 I am trying to select a list of divs (foo#) and fadeIn another div (zxcv#) on hover. I assigned a var in javascript but the end effect is only showing in foo6? <div class="foo1"><div class="zxcv1"></div></div> <div class="foo2"><div class="zxcv2"></div></div> <div class="foo3"><div class="zxcv3"></div></div> <div class="foo4"><div class="zxcv4"></div></div> <div class="foo5"><div class="zxcv5"></div></div> <div class="foo6"><div class="zxcv6"></div></div> <script type="text/javascript"> for

jquery selectors: an uncommon use case

人盡茶涼 提交于 2019-12-12 03:58:41
问题 I have to parse an html page organized this way: <li id="list"> <a id="cities">Cities</a> <ul> <li> <a class="region" title="liguria">Liguria</a> <ul> <li> <a class="genova">Genova</a> </li> <li> <a class="savona">Savona</a> </li> </ul> </li> <li> <a class="region" title="lazio">Lazio</a> <ul> <li> <a class="roma">Roma</a> </li> </ul> </li> </ul> </li> I need to extract a list of all the cities . I don't care about regions... I am using cheerio from node.js , but I added jquery to the tags