jquery-selectors

jQuery selector with variable

家住魔仙堡 提交于 2019-12-12 03:49:33
问题 I need to select all images whose filename contain a certain string (variable) using jQuery. I am using: var str='-out.'; $('img[src*='+str+']'). //do something It works but fires the following warning in Firefox: " Expected ']' to terminate attribute selector but found '.' " Would someone know how to avoid this warning ? Thank You 回答1: I think you need double quotes or single around the attribute value. Look at Jquery Docs for attr*="value" selector like this: $("img[src*='"+str+"']") OR $(

:visible selector issue

本小妞迷上赌 提交于 2019-12-12 03:40:43
问题 <ul id="portfolio" style=""> <li class="thumb one-third column mrmrs" style="display: block;"> content #1 here </li> <li class="thumb one-third column doof hidden" style="display: none;"> content #2 here </li> <li class="thumb one-third column doof hidden" style="display: none;"> content #3 here </li> </ul> This is my computed HTML source code where you can see 3 list-items where the first one has a style="display:block" whereas the other 2 has "display:none". Before that, just to let you

JQuery Selector for multiple elements of one ancestor

空扰寡人 提交于 2019-12-12 03:36:50
问题 I have a DOM structure similar to this: <div id="ans1"> <input id="in1" /> <input id="in2" /> </div> <div id="ans2"> <input id="in1" /> <input id="in2" /> </div> How can I select some of the descendants of an ancestor? Something like: $("#ans1 #in1, #ans1 #in2") 回答1: You can use the children function $("#ans1").children("#in1, #in2") You should use unique ids thought the DOM, use classes to specify elements that are the same in nature. change your children to have same class of in1 $("#ans1 >

Positioning selectors with correct dimensions that scale on different screen sizes

别来无恙 提交于 2019-12-12 03:27:54
问题 Trying to build a page layout using html and css, the page contains jQuery UI selector elements Looking to have <div id="content"> <img id="grid" src="http://placehold.it/350x250"/> </div> placed in the center of the screen, equal distance from left, right, top and bottom window edges. And a left hand menu, containing 8 images, 4x2 rowsxcols layout <div id="menu" style="width:150px;float:left;"> <b>Stock images</b><br> <ol id="selectable"> <li id="house.jpg" class="ui-state-default"><img src=

jquery not getting value from select statement on change

一笑奈何 提交于 2019-12-12 03:27:44
问题 This is really odd, but I am probably missing something simple. I have a simple select statement where a user can choose a value. onChange calls a function getDrop2() which currently I am trying to get it to alert me which option is chosen. my html is: <select onChange= "getDrop2()" id = "drop1" > <option value="0">All</option> <option value="1">Alphabetical</option> <option value="2">Brewery</option> <option value="3">Style</option> </select> My Javascript is: function getDrop2(){ var choice

How can I set the value of a hidden input field using Jquery?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 02:54:21
问题 I am attempting to set the value of a hidden input field to the same as the value of a clicked link. This is what I have attempted which doesnt work: $(document).ready(function(){ $(".delete_link").click(function(){ var deleteID = $(this).attr("data-value"); $("#delete_value").attr("value") = deleteID; }); }); The variable deleteID is correctly set. and the form for reference: <form name="delete_form" action="delete_post.php" method="POST"> <p>Please confirm you want to delete this post.</p>

Ajax calls resulting in an error[object Object]

隐身守侯 提交于 2019-12-12 02:45:59
问题 I am getting an error[object Object] while trying to pass a value through ajax calls. I am using jquery selector to get value of checkbox. And trying to pass it through ajax so that I can get only the checkbox value that I have selected. But getting an error. Thanks. Here is my code: dashboard.php if($param['aktion'] == 'save-widget-vehicle') { $page['register-fahrzeuge'] = array( 1 => array( 'Fahrzeug','aktiv',$page['script'],''), 0 => array( 'Edit-Fahrzeug','enabled',$page['script'],'',''),

jquery get the last tr with a th

核能气质少年 提交于 2019-12-12 02:37:50
问题 using jquery how do alter the css of the last tr with a th $("#mytable tr").has('th').last().parents('tr').css({'color':'blue'}); HTML <table border="1" id="mytable"> <tr> <th>row 1, cell 1</th> <th>row 1, cell 2</th> </tr> <tr> <th>row 1, cell 1 - change this</th> <th>row 1, cell 2 - change this</th> </tr> <tr> <td>row 2, cell 1</td> <td>row 2, cell 2</td> </tr> </table> 回答1: As an alternative to xdazz's answer, I'd offer: $('tr:has(th):last').css('color','blue'); References: :has() selector

displaying image after Choose File, before upload

醉酒当歌 提交于 2019-12-12 02:25:57
问题 how can after choose image and before upload (before insert in database) displaying image? this code not displaying image: var a = $('<img src="' + g.STRING.selected.replace('$file', v) + '" alt="Angry face" width="50" height="50" />'), <input type="file" name="image' > With respect 回答1: You can use the HTML5 File API (tutorial) to display the selected file. The best way is probably to use a FileReader to get a dataURL of the file and assign it to a src of an img . 回答2: I think you can check

jQuery selector NOT

依然范特西╮ 提交于 2019-12-12 01:26:52
问题 How do i select everything BUT the element with an id? <div id="test"> <p id="test"></p> <p></p> <p></p> </div> I want to be able to select the second and third 回答1: You can't have 2 elements with the id "test" but if the code was as follows: <div id="test"> <p id="test2"></p> <p></p> <p></p> </div> then you could use $("#test p").not("#test2") or $("#test p:not(#test2)") to select just the other two paragraphs. See http://api.jquery.com/not/ for the documentation for the not() method (first