jquery-selectors

What does the second argument to $() mean?

瘦欲@ 提交于 2020-02-09 17:24:46
问题 I have a jQuery code as follows; var favorites = $("#favorites"); var favoritesFooter = $("#favoritesFooter",favorites); I am not sure what does the comma mean in the 2nd statement $("#favoritesFooter",favorites); Also what would the following statement do or represent in the above case; favoritesFooter.prev().after(newHTML); 回答1: The second statement means "search for element with ID of favoritesFooter inside the jQuery object favorites ". As you're dealing with ID which should be unique, it

What does the second argument to $() mean?

坚强是说给别人听的谎言 提交于 2020-02-09 17:23:52
问题 I have a jQuery code as follows; var favorites = $("#favorites"); var favoritesFooter = $("#favoritesFooter",favorites); I am not sure what does the comma mean in the 2nd statement $("#favoritesFooter",favorites); Also what would the following statement do or represent in the above case; favoritesFooter.prev().after(newHTML); 回答1: The second statement means "search for element with ID of favoritesFooter inside the jQuery object favorites ". As you're dealing with ID which should be unique, it

What does the second argument to $() mean?

你离开我真会死。 提交于 2020-02-09 17:20:57
问题 I have a jQuery code as follows; var favorites = $("#favorites"); var favoritesFooter = $("#favoritesFooter",favorites); I am not sure what does the comma mean in the 2nd statement $("#favoritesFooter",favorites); Also what would the following statement do or represent in the above case; favoritesFooter.prev().after(newHTML); 回答1: The second statement means "search for element with ID of favoritesFooter inside the jQuery object favorites ". As you're dealing with ID which should be unique, it

jQuery - 'this' selector doesn't work inside callback function [duplicate]

筅森魡賤 提交于 2020-02-07 12:27:52
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: $(this) doesn't work in a function I'm writing post removing code in jQuery, The removing itself is made via post-request to backeds, after server returns 200, I want to delete this post on client-side. $('.delete-post').click(function() { $.post($(this).attr('href'), {}, function(data) { $(this).closest('.post').remove(); }); return false; }); However, I've noticed that inside function(data) {...) selector

jQuery - 'this' selector doesn't work inside callback function [duplicate]

雨燕双飞 提交于 2020-02-07 12:27:24
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: $(this) doesn't work in a function I'm writing post removing code in jQuery, The removing itself is made via post-request to backeds, after server returns 200, I want to delete this post on client-side. $('.delete-post').click(function() { $.post($(this).attr('href'), {}, function(data) { $(this).closest('.post').remove(); }); return false; }); However, I've noticed that inside function(data) {...) selector

Checking if a selector matches elements marked by a specific class

最后都变了- 提交于 2020-02-07 07:27:52
问题 I have a generic jQuery selector (a string): var selector = '#files li div'; and the name of a class: var myClass = 'folder'; I want to check if the selector matches elements having the class stored into myClass . As far as now I used an instance of the selector to invoke the method hasClass(): var match = $(selector).hasClass(myClass); It works, but I thought it may exist some more efficient jQuery method which allows not to create a jQuery instance to get all the elements matched by the

Checking if a selector matches elements marked by a specific class

▼魔方 西西 提交于 2020-02-07 07:27:22
问题 I have a generic jQuery selector (a string): var selector = '#files li div'; and the name of a class: var myClass = 'folder'; I want to check if the selector matches elements having the class stored into myClass . As far as now I used an instance of the selector to invoke the method hasClass(): var match = $(selector).hasClass(myClass); It works, but I thought it may exist some more efficient jQuery method which allows not to create a jQuery instance to get all the elements matched by the

jQuery :contains with html

纵然是瞬间 提交于 2020-02-03 13:23:23
问题 I have a table that contains comma separated lists of numbers like this: <td>72,76,81</td> . I'm trying to select the table cells that don't contain a particular number. This selector worked: $("td:not(:contains('76'))", $table) The issue is that there may be rows that contain '576' or '761', etc. To solve that issue, I decided to put a <span> around each number, so that it's now: <td><span>72</span>,<span>76</span>,<span>81</span></td> . My selector is now: $("td:not(:contains('<span>76<

How can I get first 4 of the childrens and wrap it into the div?

可紊 提交于 2020-02-03 10:21:29
问题 How can I find first 4 children of the parent and wrap it into div, then next 4 and so on? Google does not know! :( FROM: <div class="main"> <div>1</div> <div>2</div> <div>3</div> <div>4</div> <div>5</div> <div>6</div> <div>7</div> <div>8</div> </div> TO: <div lass="main"> <div class="pack1"> <div>1</div> <div>2</div> <div>3</div> <div>4</div> </div> <div class="pack1"> <div>5</div> <div>6</div> <div>7</div> <div>8</div> </div> </div> Any help much appreciated. I can find first 4 by: $('.main

How can I get first 4 of the childrens and wrap it into the div?

余生长醉 提交于 2020-02-03 10:20:48
问题 How can I find first 4 children of the parent and wrap it into div, then next 4 and so on? Google does not know! :( FROM: <div class="main"> <div>1</div> <div>2</div> <div>3</div> <div>4</div> <div>5</div> <div>6</div> <div>7</div> <div>8</div> </div> TO: <div lass="main"> <div class="pack1"> <div>1</div> <div>2</div> <div>3</div> <div>4</div> </div> <div class="pack1"> <div>5</div> <div>6</div> <div>7</div> <div>8</div> </div> </div> Any help much appreciated. I can find first 4 by: $('.main