Doesn't exist. But I would love that it did. 2 days ago, I made search for it, I found this one pearl of a function, you just called it and it would perform just that. Today, I can't find it for heavens. I have been through about 5 fiddle's, about 10 '00-looking webpages, Mozilla homepages, some document.Prototype then alert($("div[invoker='MyInvoker']"));, empty arrays with enumeration without relation/reference, nodes list without names or objects and lots of others. I've visited first 3 pages of Google for query "getElementsByAttribute JavaScript", "getElementsByAttribute jQuery" and couple others, until results became extremely irrelevant. I know it's possible, because I had that script, but I thought I'd remove it for now, as it stands in my way and I could find it easy anyways. It had same principle like any getElementBy* family member:

var el = getElementById("that_one_div");
el.innerHTML = "This will be the content of that one div";
alert ("The content of that DIV is: + el.innerHTML);

But with attributes instead:

var el = getElementByAttribute("attribute", "value");
el.innerHTML = "This will be the content because you have been marked with this attribute.";
alert("Content of the element: " + el.innerHTML);

Has anybody found it maybe? Or may have such snippet laying under his/her hand? I use Node.js, JavaScript (of course) and latest jQuery provided by Google API.

I found it!!

Representative of:

var el = getElementById("that_one_div");
el.innerHTML = "This will be the content of that one div";
alert ("The content of that DIV is: + el.innerHTML);

For attributes is:

    $('tag[dataname=datanamecontent]').each(function(index) {
        this.innerHTML = "This is the content of '<tag dataname=datanamecontent'";
        alert("This is the content" + this.innerHTML);
    });

this became an element! If you're not seeking for certain content, and are just seeking for <tag dataname=*> use tag[dataname] instead. This function grabs every single one of them, and performs action with each.

Keep in mind that, whole getelementbyid is pure JavaScript, the attribute selector is from the jQuery library.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.