JQuery: ahref title from underlying img alt?

If the img is inside the anchor, you could do it like this.

If the is inside the anchor, you could do it like this; $("ahref*=''" rel="nofollow">', ahref*='https://'"). Not("href*='"+location. Hostname+"'").

Each(function() { var $this = $(this). AddClass("external"). Attr("target","_blank"); var img = $this.

Children('imgalt'); $this. Attr("title", img. Length?

Img0. Alt : "Open link in new window"); }); There are a few changes here, your current selector looks at only in the first check, but then looks at all elements in your https:// check, so this will be much more efficient. Then we're checking if the current element has a inside, if it does and it has an alt attribute we use that, otherwise we give it the default title.

Or, another method, use what you have (change the selector to be efficient though) and afterwards set the titles for anchors that contain images, like this: $("a. External > imgalt"). Each(function() { $(this).parent().

Attr("title", this. Alt); }).

From what it sounds like, you are linking to an image that you want to display in an external window. When you use an image as the target of an anchor tag, it references the actual image file, not an img element, thus there is no alt tag associated with it. If, on the other hand, the image is contained in the anchor and you click it to open a new window, then @Nick's solution should do the trick..

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions