How to select elements based on .data({key: value})

In HTML I have a div with various data- attribute properties set within a JSON object, e.g.:

<div data-layout='{
      "type" : "header",
      "minHeight" :  "10%"
   }'>
   Layout
</div>

In code, is it possible to select only elements which have e.g. data-layout.type==="header" without using .each or a filter function?

I'm looking for something along the lines of:

$('[data-layout]').find('type="header"')

Answers


Using function from this answer, you can use pattern described below:

:data( {namespace} [{operator} {check}]  )

"operator" and "check" are optional. So, if you only have :data(a.b.c) it will simply check for the truthiness of a.b.c.

Read more about it here.


If you do not use header anywhere else in the data-layout attribute you can use the attribute contains selector like this:

$('*[data-layout *="header"]')

Need Your Help

Nesting async/await calls in ASP.NET MVC

c# asp.net asp.net-mvc asynchronous async-await

I am pretty new to async/await for ASP.NET MVC and have a quick question about it. My question is it necessary to use async/await on nested calls to a database? For instance:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.