I have a selector in a find function that works with jQuery 3.3.1 and before that doesn't in 3.4.0 and 3.4.1. I am using it on an xhtml jQuery document object that I have used $.parseXML on. I am using the full version of jQuery.
I have looked into the jQuery changelogs and see nothing that should affect this, as well as in the source changes on github.
I have tested the find with .class and #id and it works, but the IDs will be dynamic so I need to search by attribute name. There will also be multiple spans that I need to manipulate which is why I need a .each(function). Currently we are freezing our dependency to jQuery 3.3.1 because it works as expected but in 3.4.0+ it doesn't even enter the function.
Works:
const xmlDoc = $.parseXML(`<?xml version="1.0" encoding="windows-1252" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns:dd="DynamicDocumentation"> <head> <title></title> </head><body><span dd:drop_list_uuid="9999">mydrop1</span></body></html>`); const $xml = $(xmlDoc).find('body'); $xml.find('span[dd\\\\:drop_list_uuid]').each(function() { console.log($(this).text()) });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Does not work:
const xmlDoc = $.parseXML(`<?xml version="1.0" encoding="windows-1252" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns:dd="DynamicDocumentation"> <head> <title></title> </head><body><span dd:drop_list_uuid="9999">mydrop1</span></body></html>`); const $xml = $(xmlDoc).find('body'); $xml.find('span[dd\\\\:drop_list_uuid]').each(function() { // This is the line that doesn't work console.log($(this).text()) });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
Problem solved here. 3.4.0+ gets rid of sizzle.
"the new versions of jQuery use querySelectoAll without sizzle. So many sizzle syntaxes don't work anymore.
A namespaced attribute query was probably implemented in sizzle." -jakecigar
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.