jquery-selectors

Uncaught TypeError: Cannot call method 'replace' of undefined

本秂侑毒 提交于 2020-01-03 17:43:12
问题 $(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

Retrieve and modify :before element with jQuery

筅森魡賤 提交于 2020-01-03 16:47:51
问题 I want to select an element which was created by the CSS selector :before . I tried it by using $('#element:before') , but that did not work, because it selected the whole element and not only the :before element. Here is the sample code: DEMO In that example, only the string "1. " should be red, not the whole string. Any idea how to do this? 回答1: JQuery cannot set css properties on :before content, since it is not contained in an element. If you want to be able to manipulate the color of the

Select previous element using jQuery selector only

↘锁芯ラ 提交于 2020-01-03 13:02:31
问题 I need to select the previous element using only a jQuery selector. <li class="collapsable"> <div class="hitarea collapsable-hitarea"></div> <span id="devicelist" class="ankr">Device List</span> <ul id="ultree"> <li type="dev" device="/dev/sdh1" id="dev0" class="litab"> <img height="20px" width="20px" src="../Images/drive.png" class="dicon"> <a class="ankr dn" href="#">'/dev/sdh1'</a> </li> </ul> </li> $(document).on("click","#devicelist,**Here Selector will be used**",this,function(event){

Child selector deprecated [duplicate]

筅森魡賤 提交于 2020-01-03 09:08:35
问题 This question already has an answer here : Closed 7 years ago . Possible Duplicate: What is the new proper way to use a child selector with a context node in jQuery? From the jQuery docs: Note: The $("> elem", context) selector will be deprecated in a future release. Its usage is thus discouraged in lieu of using alternative selectors. http://api.jquery.com/child-selector/ What would be an alternative selector for this? 回答1: $(context).children('elem') also $("> elem", context) is deprecated,

Child selector deprecated [duplicate]

别来无恙 提交于 2020-01-03 09:08:10
问题 This question already has an answer here : Closed 7 years ago . Possible Duplicate: What is the new proper way to use a child selector with a context node in jQuery? From the jQuery docs: Note: The $("> elem", context) selector will be deprecated in a future release. Its usage is thus discouraged in lieu of using alternative selectors. http://api.jquery.com/child-selector/ What would be an alternative selector for this? 回答1: $(context).children('elem') also $("> elem", context) is deprecated,

jQuery populate dynamic created select box from another select

心不动则不痛 提交于 2020-01-03 05:26:08
问题 I have a form where you can dynamically add new rows via jQuery. It creates the elements fine. However, I have a select box on the new row. When it is created, it is empty. I need to populate it from the first select box of that type (class). Here is the HTML... <select class="cyclePoSelect" name="poNumber[]" style="WIDTH: 100px"> <option value="0" selected="">Select One</option> <option value="VE-13475">VE-13475</option> <option value="VZ-61300">VZ-61300</option> </select> <select class=

How to remove all Attributes by attribute name starts with

久未见 提交于 2020-01-03 04:55:33
问题 I would like to remove all the attributes that attribute name starts with 'data-val' in the fields that has a class 'read-only-state' jQuery("[data-val^='tr']" ) This will give attribute 'data-val' value that starts with 'tr' But i need to remove all the attributes that starts with 'data-val' in the matched elements. How can i do it? 回答1: You can use vanilla javascript's attributes for this: $('.read-only-state').each(function() { // get the native attributes object var attrs = this

Select the nearest DOM element with jQuery

99封情书 提交于 2020-01-03 03:28:46
问题 How to access the div with specific class that is on the same level of DOM using jQuery? I've tried .closest() but it doesn't find the element. For example: <!-- foreach loop starts { --> <fieldset> <legend>Values</legend> <div class="characteristic-values"> <!-- many divs inside --> </div> <input type="button" class="add-charactersitic-value" value="Add Value" /> </fieldset> <!-- } foreach loop ends --> And JavaScript that tries to access the "charactersitic-values" but without success:

Is it possible to mix multiple selector and filter using jQuery?

旧街凉风 提交于 2020-01-03 03:19:05
问题 I know there's the possibility, using jQuery, to mix Multiple Selector with Multiple Attribute Selector and, indeed, I used it. For example, this works fine: $('input[type="checkbox"][name^="selected"]:checked', theForm).length In my example, "theForm" is a string containing "#form1" which I use to refer to my form that has the attribute id="form1". Well, that said, the question is: is it possible mixing the above with jQuery filter? Here is a code example: var myVar = $('input[name^="modcc_"

Opposite of .find()

不问归期 提交于 2020-01-02 08:30:13
问题 Is there an opposite of .find()? Where $('.myclass').except('#myid'); Would grab all elements with .myclass except the element with #myid. I know I could do $('.myclass[id=myid]') in this example, but seems like it would be helpful in other cases. Thanks EDIT: Thanks for the responses! Looks like I just missed seeing .not() and :not() in the documentation. 回答1: $('.myclass').not('#myid'); http://api.jquery.com/not/ 回答2: Try .not() – it removes any element matching the selector. 回答3: $('