Can i get and element by data added with jquery? For Example
function first() {
var modal_body = $('.modal-body');
modal_body.data('id',4)
}
function second() {
var modal_body = $('.modalbody[data-id=4]');
}
I've already tried this example, but it doesn't work because the element doesn't have data-id. Jquery saves data internally and creates an empty object called $.cache.
Is there any posibility to get the element, which contains data added with Jquery?
Unfortunately, no.
As you said, the data properties are added internally by jQuery. The only way to achieve what you want is to set attributes directly:
Which makes it available as
.data('id')as well.Another alternative would be to use
.filter():Demo below.