How to access a jquery without id?

Asked

Viewed 64 times

0

I always completed a jquery using the command: $('#id_1'), but always in a html body that has id. How do I access an html body that does not have id, using the attribute data-uid in my case below?

<img data-uid="_b03bc8304532" ui-sref=".image({uidImage: 
&quot;_b03bc8304532&quot;})" width="450" height="450">
  • 1

    $("[data-uid=\"_b03bc8304532\"]")

2 answers

3

It may be so:

$('*[data-uid="_b03bc8304532"]');

Selects all elements with this data-uid. I switched to a span to demonstrate:

$('*[data-uid="_b03bc8304532"]').html('texto alterado');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


<span data-uid="_b03bc8304532"></span>

  • 1

    If he wants 1 can use the .each() after this command

  • 1

    In the case each, it will be able to manipulate all the elements that return

1


Browser other questions tagged

You are not signed in. Login or sign up in order to post.