user1568736
user1568736

Reputation: 133

workaround to using ID in <a> to call function

I'm using an XML file that has a number for each section. The page loads a link for each section of the XML and puts the article number in the URL parameter (page.html?aid=###). When the link is clicked an overlay iframe pops up the with more information about that article. is calling the overlay iframe popup but I can't use more than one of the same ID for a page.

$(function(){
    $('#b1').frameWarp();
});

Instead of using ID="b1", am I able to use each article number for the id? I cannot use class instead of ID. Would there be another way to do this?

Upvotes: 1

Views: 110

Answers (2)

user1568736
user1568736

Reputation: 133

Here is the answer courtesy of benalpert on reddit: $('.b1').each(function() { $(this).frameWarp(); }) This allows the class to be used instead of ID without error. Thanks to everyone for the help.

Upvotes: 0

Chris Pratt
Chris Pratt

Reputation: 239290

You could use $('a[id^="b"]'), but that's hugely inefficient and will probably match more than what you want it to. Alternatively, you could filter on a regex:

$('a').filter(function(){
    var re = /^b[0-9]+$/;
    return re.test($(this).attr('id'));
}).frameWarp();

It's not much more efficient, if at all, but at least it would rule out false positives.

Upvotes: 2

Related Questions