I tried to get the image height and width from a href link image, but no luck. is there anyone know how to solve this problem?
here is the code:
<a href="/images/int_kit_a_set.jpg" class="upload">
<img src="/Assets/images/int_kit_a_set_thumb.jpg"
ondragstart="return false" height="108" width="144" alt="" />
</a>
Your HTML:
<img src="/Assets/images/int_kit_a_set_thumb.jpg" ondragstart="return false" height="108" width="144" alt="" />
Javascript w/jQuery:
var image = $("<img />").attr("src", $(".upload").attr("href"));
$(document).append(image);
alert(image.height());
alert(image.width());
image.remove();
I didn't test the javascript... but I'm not really sure your question is clear... so maybe this is what you wanted, maybe not.
Essentially, I'm grabbing the HREF attribute of the link, creating a new image on the page with that url, measuring the image, and then removing it from the DOM.
You could add a style to the image which placed it off screen or something... but you'd have to mess with it to find something that worked cross-browser. Some browsers don't consistently load images which aren't visible. I'm also not sure if you'd run into any timing issues with my script.
Putting it all together:
alert( new Image().src = $('.upload').attr('href')).width );
Related
I have this broken img tag and it works fine in Chrome and Edge browser. It loads all the images even though there is something wrong with the src attribute.
<a href="https://www.prikkabelled.nl/feestverlichting-voor-de-achtertuin/">
<img src="<img width="806" height="605" src="https://www.prikkabelled.nl/wp-content/uploads/Feestverlichting-voor-in-de-achtertuin.jpg" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="" srcset="https://www.prikkabelled.nl/wp-content/uploads/Feestverlichting-voor-in-de-achtertuin.jpg 806w, https://www.prikkabelled.nl/wp-content/uploads/Feestverlichting-voor-in-de-achtertuin-152x114.jpg 152w, https://www.prikkabelled.nl/wp-content/uploads/Feestverlichting-voor-in-de-achtertuin-768x576.jpg 768w, https://www.prikkabelled.nl/wp-content/uploads/Feestverlichting-voor-in-de-achtertuin-253x190.jpg 253w, https://www.prikkabelled.nl/wp-content/uploads/Feestverlichting-voor-in-de-achtertuin-506x380.jpg 506w, https://www.prikkabelled.nl/wp-content/uploads/Feestverlichting-voor-in-de-achtertuin-600x450.jpg 600w, https://www.prikkabelled.nl/wp-content/uploads/Feestverlichting-voor-in-de-achtertuin-200x150.jpg 200w" sizes="(max-width: 806px) 100vw, 806px" />
</a>
However, Internet Explorer refuses to loads the images. I know this should be fixed at the source, but I am not responsible for that.
Is there some kind of frontend fix we can apply so that the images will load in IE?
I have tried removing the src attribute all together but to no avail
jQuery( "img.attachment-post-thumbnail" ).removeAttr('src');
Your HTML is broken. It is not correct to nest img tags. If you can't fix the terrible HTML, maybe try some js to pull the url out of the malformed src attribute of the first tag??
$('a img').each(function(){
$(this).parents('a').html($(this).attr('src'))
})
This seems to be a Safari exclusive bug, and I can't seem to find any information on why it might even be happening.
It's only on Safari, and only using SVG.
I am using the Data Attribute rollover technique using jQuery.
$("img.rollover").hover (->
imgRolloverSwap($(#))
), ->
imgRolloverSwap($(#))
imgRolloverSwap = ($img)->
srcName = $img.attr('src')
$img.attr('src', $img.data('rollover'))
$img.data('rollover', srcName)
The SVG is embedded with the IMG tag, and basically all it does is switch out the rollover image for the one inside the data attribute.
My HTML is thus:
<div id="social-links">
<a href="https://www.facebook.com/pages/StackCommerce/220449001487225">
<img data-rollover="/assets/img/footer/facebook-rollover.svg" class="rollover" type='image/svg+xml' src="/assets/img/footer/facebook.svg" />
<!-- <img class="rollover" src="/assets/img/footer/facebook.svg" alt="facebook link" target="_blank"> -->
</a>
<a href="https://www.linkedin.com/company/stackcommerce">
<img class="rollover" src="/assets/img/footer/linkedin.svg" alt="linkedin link" target="_blank">
</a>
<a href="https://plus.google.com/u/0/b/104759401634432683234/104759401634432683234/aboute">
<img class="rollover" src="/assets/img/footer/google.svg" alt="google plus link" target="_blank">
</a>
<a href="https://twitter.com/stackcommerce">
<img class="rollover" src="/assets/img/footer/twitter.svg" alt="twitter link" target="_blank">
</a>
</div>
The CSS(Sass) is this:
#social-links {
#extend .col-xs-12, .col-sm-3, .col-md-2;
a {
#extend .col-xs-3, .col-sm-6;
margin-bottom: 15px;
}
img {
#extend .img-responsive;
}
}
However, on first hover the image works, but when you roll off, the image gets smaller.
This happens if you use the jQuery technique or if you use vanilla JS to change out the src name with a regular expression.
This doesn't happen to other image formats, and I have tried setting different 100% widths on nearly every element of the cascade.
Fixes from these threads don't seem to be fixes:
SVG resizes on hover in safari only
Scaling/Resizing SVG in an HTML
Rollover SVG images resizing in Safari and IE
Perhaps someone can shed some light on why this is happening, or a technique to help in Safari?
You can see it here on this page, and at the bottom of it in the footer.
http://beta.stackcommerce.com.s3-website-us-east-1.amazonaws.com/publishers/
Thanks in advance!
I’ve made a cardspread program that is based on the source of the image. It works allright, but it is loading slowly, because now 78 different cards are loaded. I like to speed up the loading and I thought I needed an extra item per DIV. So I added an ALT-tag to each image. Like this:
<div id="kaart1">
<alt=kaart14.jpg>
<img src="images/kaart1.jpg" width="110" height="180" onclick="showDiv(event)>
</alt=kaart14.jpg>
</div>
Now I need only 1 image to load 78 times, which is faster. The problem which I am facing now is that I want to read the alt value into a variable (in this case: kaart14.jpg).
I’ve tried :
$('.status').click(function() {
var status = $(this).attr('alt');
});
But that stays empty. Does anyone have a suggestion how to solve this in Javascript or jQuery?
First, there is no <alt> tag. It is used as alternative to <img>. The value is displayed if the image is not loaded.
It is just plain text. If you put a url there, it will just display the url and not the image itself.
Eg:
<img src="myphoto.jpg" alt="This is my photo">
There is no performance gain if you use alt or not, but you definitely SEO
Your alt attribute should be like
<div id="kaart1">
<img src="images/kaart1.jpg" alt="kaart Image" width="110" height="180" onclick="showDiv(event)>
</div>
alt is an attribute of the img tag,its not a tag itself.And as #Bergi said,the alt attribute will not be an another image.It may be the description.
I am new for script and jQuery
I’m using a multilanguage script to change from language. Now I'm having troubles to change from a language by using the image,
<img src="/flags/us.png" alt="en_EN" />
<img src="/flags/it.png" alt="it_IT" />
<img src="/flags/fr.png" alt="fr_FR" />
here after i dnot know how to use this image tag
what i want from this image tag , when i am click this image i want the alt value of corresponding image click.
Hoe to get it...
its possible or else give any other idea
thanks
Kumar
Put a class in your anchor and try this
<img src="/flags/us.png" alt="en_EN" />
<img src="/flags/it.png" alt="it_IT" />
<img src="/flags/fr.png" alt="fr_FR" />
$('a.lang img').click(function(){
var alt=$(this).attr('alt');
});
<a class='lang_link' href="#"><img src="/flags/us.png" alt="en_EN" /></a>
Assuming your links have a class of lang_link, you can look inside the link to see what language should be chosen.
$('.lang_link').click(function(){
var lang = $(this).find('img:first').attr('alt');
});
I was trying to put a link on an image. When the mouse is over the image, the image changes from login_button_22.jpg to login_button_11.jpg. I am using the following piece of code, which is working for IE but not for chrome and others. Any ideas how to modify it, to work for all explorers? Thanks
<a href="#top"
onmouseover="document.getElementById('myimage1').src='img/login_button_22.jpg';"
onmouseout="document.getElementById('myimage1').src='img/login_button_11.jpg';" >
<img src="img/login_button_11.jpg" id="myimage1" />
</a>