Valeka
Valeka

Reputation: 123

Convert attribute into string

I know this is really basic javascript but I'm really not so familiar with javascript.

What I'm trying here is to add prettyPhoto arguments where I want to be. First I get href attribute from link, then I convert it to string, then I take last 4 letters to check is it link to image or to some HTML page. And this code works fine but still my Firebug sends me an error:

TypeError: $hrefy is undefined

txt = $hrefy.toString(); 

How script can work if $hrefy is not defined and how to define it well. This error blocks only javascript code for filtering my portfolio, while other js work fine.

$(document).ready(function(){
$("a[data-rel^='prettyPhoto']").prettyPhoto();

$hrefy = $("article a").has('img').attr("href");
txt = $hrefy.toString();
var lastChar = txt.substr(txt.length - 4);
if (lastChar=='.jpg') {
    $('article a').has('img').attr('data-rel', 'prettyPhoto'); 
}

$('a img').click(function () {  
    var desc = $(this).attr('title');  
    $('a').has('img').attr('title', desc);  
});  

});

Upvotes: 1

Views: 1506

Answers (1)

Marcus Vinicius
Marcus Vinicius

Reputation: 1908

After looking into the source of the page you've linked, I've noticed that there is no <article> element declared anywhere. So, your jquery selector does not return anything and attr('href') is undefined.

Upvotes: 1

Related Questions