I have the following elements
<li data-attr="sessionContext='test session'"></li>
<li data-attr="sessionContext='test session 12345'"></li>
// I want to get all elements with [data-attr=someContext*=] -doesn't
matter someContext= value, but doesn't work
$("[data-attr]") // gets all elements, but not sessionContext only
$("[data-attr='sessionContext=test session']") // works but for single element only
Using a selector, you can try this:
$('[data-attr="sessionContext=test session"]')
// will return the element sessionContext=test session
$('[data-attr^="sessionContext=test session"]' )
// will return all that begin with sessionContext=test session
$('[data-attr$="sessionContext=test session"]' )
// will return all that end with sessionContext=test session
$('[data-attr*="sessionContext=test session"]' )
// will return all that contain sessionContext=test session
Try this:
$("[data-attr^=sessionContext]")
^ will match anything starting with sessionContext
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.