It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

add class to img with javascript

add class to img with javascript

Postby trinity on Sat Sep 19, 2009 12:50 pm

Hi people,

I am new to this phorum so let me first say: HI 8)

I have a wysiwyg-editor on my website so people can change their own page. The editor has a button which opens their personal photoalbum, and when you click 'add' under a picture, the picture is added in the editor. When you click on 'view html' you can see that the following code has been added: <img src="name.jpg">

I want to change the code so that the following code will be added: <img src="name.jpg" class="picture_own_page">.

I want to do this because I want to align the picture automatically and give it the right margins. I've tried adding code like 'var sImgSrc = (sImgSrc + " class=tekstfoto");' but that did not do the trick. Unfortunately I am not good at javascripting, and now I am stuck.

This is the original code:

On the editor page:
Code: Select all
function insertImage() {
  if (isHTMLMode){alert("vink html bewerken uit");return;}
  var sImgSrc=("http://www.tulipejaune.nl/fotoalbum/" + document.sImgSrc);
   document.editor.focus();
  if(sImgSrc!=null) cmdExec("InsertImage",sImgSrc);
}

function cmdExec(cmd,opt) {
  if (isHTMLMode){alert("vink html bewerken uit");return;}
  document.editor.document.execCommand(cmd,"",opt);editor.focus();
}


On the photo album:

Code: Select all
<script language="javascript" type="text/javascript">
function fotoinvoegen(bestandsnaam)
{
opener.document.sImgSrc = bestandsnaam
opener.insertImage()
window.close()
}
</script>

<a href="javascript:fotoinvoegen('name.jpg')" class="wijziglink">add</a><br>


Can anyone help me?
trinity
 
Posts: 1
Joined: Sat Sep 19, 2009 12:35 pm

Who is online

Users browsing this forum: No registered users and 3 guests