Karin Karin - 6 months ago 10
HTML Question

add/append alt value dynamically?

Newbie (perhaps stupid) question: How can I use the value of "alt" in the code below to add/append it to "img" (between the "img" and "a" end tags)? I haven't been able to find examples out there on anything else than how to add/append hard coded text, but I want it to be done dynamically.

$html .= '<a href="#imgshow" data-transition="pop" data-index="'.$i.'" data-rel="dialog" id="thumb">
<img src="https://[someurl]/'.rawurlencode($this->_decode_path($xml->COM->MOVIE[$i]->attributes()->dbIcoFilename)).'" alt="'.$xml->COM->MOVIE[$i]->attributes()->nameS.'">
</img></a>'

Answer

jQuery for all img with afteralt css class (php and jQuery codes);

PHP;

$html .= '<a href="#imgshow" data-transition="pop" data-index="'.$i.'" data-rel="dialog" id="thumb">
        <img src="https://[someurl]/'.rawurlencode($this->_decode_path($xml->COM->MOVIE[$i]->attributes()->dbIcoFilename)).'" alt="'.$xml->COM->MOVIE[$i]->attributes()->nameS.'" class='afteralt'>
        </img></a>'

jQuery:

$.each($("img.afteralt"), function() { 
  $(this).after($(this).attr("alt"));
});
Comments