Reputation: 680
I want to hide an image on page load, depending on its title This does not seem to work.. when i put this in my code, i get an alert for all the images that have a title (which is correct):
$('article a.tooltip img').load(function(){
if(this.title != ""){
alert(this.title);
}
});
In my CSS file I disabled the display of all images at first:
.contact a.tooltip{
display: none;
}
now i want to show all the images with non empty title, which doesnt work:
$('article a.tooltip img').load(function(){
if(this.title != ""){
this.show();
alert(this.title);
}
});
Upvotes: 2
Views: 742
Reputation: 680
article a.tooltip img is not hidden. .contact a.tooltip is hidden.
Change
$('article a.tooltip img').load(function(){
if(this.title != ""){
this.show();
alert(this.title);
}
});
to
$('article a.tooltip img').load(function(){
if(this.title != ""){
$(this).parent().show();
alert(this.title);
}
});
Upvotes: 0
Reputation: 10030
$("article a.tooltip img").each( function() {
var t = $(this).attr("title");
if(t!=// some title) {
$(this).parent("a.tooltip").show();
}
else {
$(this).parent("a.tooltip").remove();
}
Upvotes: 0
Reputation: 972
Try to use $(this)
and .attr()
like this:
$('article a.tooltip img').load(function(){
if($(this).attr('title') != ""){
$(this).show();
alert($(this).attr('title'));
}
});
hope it can help
Upvotes: 0
Reputation: 2247
article a.tooltip img is not hidden. .contact a.tooltip is hidden.
Change
$('article a.tooltip img').load(function(){
if(this.title != ""){
this.show();
alert(this.title);
}
});
to
$('article a.tooltip img').load(function(){
if(this.title != ""){
this.parent().show();
alert(this.title);
}
});
Upvotes: 4