简体   繁体   中英

on dom ready change html source using js

I'm stuck with tinymce align problem. When I align text content to image let say left content preview look ok but on rendering content I'm getting source like this

<p>
   <img width="205" height="154" alt="" src="/Content/uploads/images/mypic.jpg" left;"="">
</p>

now I want to change this snippet left;"=" to align="left" using javascript so when user loads page and when js recognize snippet left;"=" to automatically change to valid align property align="left" .

How to do that?

I haven't seen anything like this left;"=" generated automatically. I'm not sure why it is generated, but you can remove the left attribute and add align attribute to your image .

Better try like this,

 $(document).ready(function(){
    if($('img').attr("left")) {
      $(this).removeAttr( 'left');
      $(this).attr("align","left");
    }
 )};

When I test this, you end up with an empty left;" attribute on the image, so you can do this:

if ($('img').attr('left;"') !== undefined) {
    $('img').attr('align', 'left');
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM