ngplayground
ngplayground

Reputation: 21657

jquery to find data-attr where

Using the url of the page I have been able to get the value edc into a variable but what I need to do is find the data-ttl where data-uri is equal to edc.

If PHP this would be easy but I'm unsure how to go about it in jQuery

domain.com/media-centre/video/edc

HTML

            <li class="item" data-id="id-7" data-type="services">
            <a href="#" data-uri='edc' data-ttl='Engineering'>
                    <img src="/assets/img/media-centre/videos/edc.png">
                    <div class="itemcontent">
                        <h2>Engineering</h2>
                    </div>
                </a>
            </li>

JQUERY - my tried and failed attempt

var permatitle = $('a').attr('data-uri').val('edc');

SORTED

var permatitle = $('a[data-uri="edc"]').attr('data-ttl');

Upvotes: 0

Views: 474

Answers (1)

webdeveloper
webdeveloper

Reputation: 17288

Use this selector:

$('a[data-uri="edc"]')

Then you can read data attribute like:

$('a[data-uri="edc"]').data('edc')

Upvotes: 1

Related Questions