jquery-selectors

Why doesn't this jquery code work?

本小妞迷上赌 提交于 2020-01-05 08:18:14
问题 I have this code in my application.js file, but it doesn't seem to work: $("#video_div img").click(function() { $("div.embed").toggle(); }); Here's the HTML my browser sees: <div id="video_div"> <img src="http://i3.ytimg.com/vi/fTWpHknumdg/hqdefault.jpg" style="width: 200px; "> <div class="embed"> <object width="300" height="194"><param name="wmode" value="opaque"><param name="movie" value="http://www.youtube.com/v/fTWpHknumdg?version=3"> <param name="allowFullScreen" value="true"> <param

what does this jquery $('.some-class',$('#some-id')) mean?

感情迁移 提交于 2020-01-04 14:04:26
问题 i know the meaning of $('.some-class') and $('#some-id') , but i do really not know the meaning of $('.some-class',$('#some-id')) , hoping some one can explain it for me, many thanks. 回答1: You have selector with context , some-class will be looked up in element with in element with id some-id . '.some-class' is selector and $('#some-id') is context The syntax in the jQuery documents for selector is jQuery( selector [ , context ] ) you can read more about selectors here Without context $('

jQuery - showing first three images of a gallery; hiding the remainder

笑着哭i 提交于 2020-01-04 14:03:44
问题 I have an list of images with the following markup: <a href="#" id="toggle-16561" onclick="toggleImages(16561); return false;">show images</a> <div class='image-container-box clearfix' id='image-container-box-16561'> <span class='image-box'> <a href="/images/1.jpg"><img src="/images/1_thumb.jpg" /></a> </span> <span class='image-box'> <a href="/images/2.jpg"><img src="/images/2_thumb.jpg" /></a> </span> etc .... </div> </div> I could have a bunch of these on a web page (like 20 or more). I

jQuery selector problem when using a single parenthesis

家住魔仙堡 提交于 2020-01-04 09:13:38
问题 If I include a single parenthesis in a :contains selector I get an error. e.g. $("a:contains('Speed (mph')") returns the error Syntax error, unrecognized expression: (mph') if I add the closing parenthesis at the end, the statement runs fine. however, I need to be able to query where there is often a single parenthesis. What's going on here and how do I sidestep this? EDIT In my actual code the :contains part is passed in as a variable e.g var searchText = 'Speed (mph'; var result = $("a

setting default root element in jquery

若如初见. 提交于 2020-01-04 03:57:48
问题 jQuery currently uses window as its default element so any call like $('div') will look for div tags inside window . Is there any way to change defaults on jQuery like: $.defaultRoot = $('.anyOtherRootElement'); $('div').text("Hello"); this will select any div inside the elements containing .anyOtherRootElement class. Thanks in advance Upate just an update refining the question a bit more here: I would like to perform the actions above based on external queries coming from external script

How to find whether Current TD is last TD in TR

﹥>﹥吖頭↗ 提交于 2020-01-03 21:04:33
问题 I have a single row and multiple <td> s in it. In one of my functions I come across a situation where I have to find out whether my currentSelectedTD is the last <td> in the row so that I can treat it diffrently. I tried $(currentSelectedTD).is(":last") which is not working and always returns true . I have also tried couple of other possibilities which are not working. Thanks in advance. 回答1: You can use .next() to check if the element has the immediately following sibling. if( $

Select only parent, exclude everything else while click()

烈酒焚心 提交于 2020-01-03 19:04:07
问题 I have a #container and buttons which are children to this container. When I click the container itself (the white space around the buttons), I want it to change its background color but I want nothing to happen when I click the buttons. Selecting the #container in jquery, though, makes clicking the buttons change the bg as well... <div id="container"> <div class="button> <span class="text">Button 1</span> </div> <div class="button> <span class="text">Button 2</span> </div> </div> $("

Select only parent, exclude everything else while click()

久未见 提交于 2020-01-03 19:03:46
问题 I have a #container and buttons which are children to this container. When I click the container itself (the white space around the buttons), I want it to change its background color but I want nothing to happen when I click the buttons. Selecting the #container in jquery, though, makes clicking the buttons change the bg as well... <div id="container"> <div class="button> <span class="text">Button 1</span> </div> <div class="button> <span class="text">Button 2</span> </div> </div> $("

I cannot select <title> tag in Atom XML using jQuery

妖精的绣舞 提交于 2020-01-03 18:14:54
问题 I get Atom data through Ajax using jQuery. I write $(xhr).find('entry id').eq(0).html(); is OK. But $(xhr).find('entry title').eq(0).html(); can not select anything. title tag is actually exist. Please help. Thank you! 回答1: That is because there is no title element in the Atom XML. The actual name is atom:title if the XML namespace http://www.w3.org/2005/Atom was mapped to the namespace prefix atom . Your problem is that jQuery is a HTML library, not an XML library. Therefore, it has some

Uncaught TypeError: Cannot call method 'replace' of undefined

社会主义新天地 提交于 2020-01-03 17:44:29
问题 $(this).find("input[name=amount]").val($(this).find("input[name=amount]").val().replace('$', '')); Keep getting this error on my developer tools. I just want to replace the character $ with nothing which is '' Thoughts? 回答1: Your error just says that there is no element that matches your selector, so element.val() is returning undefined , which has no replace method. Try debugging it and console.log() at each step. Also, you don't need to search for the element twice. Just store it in a