0

Can anyone tell me if it's possible with jQuery to use a data-link-title instead of a class or an ID?

I have the following code here but instead of the class ".child" i would like to use the given data-link-title "Sound Packs" inside of the html.

$(document).ready(function() {$('.child').attr('href','https://stackoverflow.com/');});

The html looks like this:

<a data-link-title="Sound Packs" class="child">Sound Packs</a>
  • Based on [your reposting the question](https://stackoverflow.com/questions/60139649/replace-class-with-data-link-tile-in-jquery), you don't seem to understand how to apply [the answers here](https://stackoverflow.com/questions/5324415/select-elements-by-data-attribute-in-css) to your code. The strings you pass into jQuery's `$()` function are CSS selectors. As the answers to the linked question explain, [attribute selectors](https://www.w3.org/TR/selectors-3/#attribute-selectors) use `[attributename]` (for just "does it have the attr" or `[attributename='value']` for looking for... – T.J. Crowder Feb 09 '20 at 18:07
  • 1
    ...a specific value. (There are other forms as well, see the link for details.) So in this case, if you want to match the link that has `data-link-title="Sound Packs"`, you'd use `$("[data-link-title='Sound Packs']")`. – T.J. Crowder Feb 09 '20 at 18:08

0 Answers0