jQuery .each() returns DOM element and not a jQuery object

The documention is not wrong but you may misunderstand what a jQuery object is. The jQuery object is returned by the $() function. So $(“span[id$=’_TotalItemCost’]”) is one jQuery object which contains every span element selected. Using .each() will iterate over the elements contained in the jQuery object. This is why this is a DOM node … Read more

Select elements without any class [duplicate]

Use :not() and the attribute not selector [att!=val] to filter out elements with a non-empty class attribute: $(‘span:not([class!=””])’) jsFiddle preview Note however that [att!=val] is a non-standard jQuery selector, which means the selector cannot be used in CSS or with document.querySelectorAll(). If you’re like me, and you’re a stickler for following the standards and so … Read more

jQuery – selectors on a html string

First, use jQuery.parseHTML to parse the HTML into an array of elements; then you’ll be able to convert it to a jQuery collection and use filter to restrict the collection to elements matching a selector. var html=”<td class=”test”>asd</td>” + ‘<td class=”second”>fgh</td>’ + ‘<td class=”last”>jkl</td>’; var text = $($.parseHTML(html)).filter(‘.test’).text(); console.log(text); <script src=”https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js”></script>

jQuery – Click event on elements with in a table and getting element values

Unless otherwise definied (<tfoot>, <thead>), browsers put <tr> implicitly in a <tbody>. You need to put a > tbody in between > table and > tr: $(“div.custList > table > tbody > tr”) Alternatively, you can also be less strict in selecting the rows (the > denotes the immediate child): $(“div.custList table tr”) That said, … Read more

JQuery create new select option

Something like: function populate(selector) { $(selector) .append(‘<option value=”foo”>foo</option>’) .append(‘<option value=”bar”>bar</option>’) } populate(‘#myform .myselect’); Or even: $.fn.populate = function() { $(this) .append(‘<option value=”foo”>foo</option>’) .append(‘<option value=”bar”>bar</option>’) } $(‘#myform .myselect’).populate();

Get text from anchor tag

Use .text() for this: alert($(this).text()); If you wanted the markup (.text() removes tags and such), use .html() alert($(this).html()); In this case there’s no difference, if instead you had this: <a href=”http://www.google.com/”>Google <span>(External)</span></a> Then there would be: $(this).text() //”Google (External)” $(this).html() //”Google <span>(External)</span>”