How to style the <alt> tag string?

Is there any way to style alt? With javascript? With pseudo attributes? eg:

<img src="foo.jpg" alt="<h1>This is the caption</h1><p>This is some text</p><p>Another text</p>" />

??

And javascript (I use the jQuery framework) does something like this?

Get value of <alt> from <img>
make value between <h1></h1> css font-size:22px; color:green;
make value between <p></p> css font-size:14px; color:black;

BTW: javascript reads the alt tag of the image and displays them on the screen .. so that this text will be displayed not only if img is not loaded.

+3
source share
5 answers

alt, , . , , . <img>, ( IE).

, , title , . alt IE , . , . , . , .

+10
+3

, , . JavaScript/JQuery, DIV , .

, , , , .

. ( ) alt:

<img id="myimg" src="foo.jpg" alt="This is the caption|This is some text" />

, , , :

var img = $('#myimg');
var alt = img.attr('alt').split('|');

var divContents = '<h1>' + alt[0] + '</h1><p>' + alt[1] + '</p>';
+2

Source: https://habr.com/ru/post/1776857/


All Articles