morizvonlanga morizvonlanga - 2 years ago 165
HTML Question

jQuery find element with custom attribute 1 and 2

I've written this code to load dynamic content:

var path = $(this).attr('path')

and this to create anchor links when the content is loaded:

var title = $(this).attr('title');
window.location.hash = title ;

And this part to check which content was loaded:

var title = $('.item').attr('title');
if (window.location.href.indexOf(title) > -1) {
console.log("found it");

No I would like to load the content via the anchor link so I need to get a element with the title who fits to the path. The HTML markup looks like this:

<div class="item" path="/mainfolder/subfolder/item/" title="I'am the title">

Do you have any ideas to do something like that? I just need to know how I'am able to search for elements with:
attribute 1 which has attribute 2

Thanks for answers guys!

Answer Source

This is how to select it ^^

if($('[path="/mainfolder/subfolder/item/"]').length > 0){
if($('[title="I\'am the title"]').length > 0){

if($('[path="/mainfolder/subfolder/item/"][title="I\'am the title"]').length > 0){
<script src=""></script>

<input class="item" path="/mainfolder/subfolder/item/" title="I'am the title"/>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download