when i want use some html codes into the some scripts, then it doesn't work or visitor just see source of HTML that i inserted! no its effect ... sample problem: <script type="text/javascript"> var sayHello = new LiveValidation('sayHello', { validMessage: '<br/><a href="index.html"><img src="hello.jpg" border="0" valign="bottom"></a>', wait: 500}); sayHello.add(Validate.Presence, {failureMessage: "test"}); sayHello.add(Validate.Format, {pattern: /^hello$/i, failureMessage: "test" } ); </script> Code (markup): do i need use document.write to cover HTML codes ? then its working ?
The proper way of adding HTML is via the DOM. Here's how you would insert an image: var image = document.createElement( 'img' ); image.src = 'http://www.imagelink.com'; image.setAttribute( 'width', '100px' ); image.setAttribute( 'height', '100px' ); document.body.appendChild( image ); Code (markup): The quickest way, but will write your HTML wherever your script is located on the page, is using: document.write( '<p>here is some html</p>' ); Code (markup): You can also use innerHTML: document.getElementById( 'my_div' ).innerHTML = '<p>here is some html</p>'; Code (markup):
If you write many dom elements use innerHTML property, or you can use dom node manipulation for a single element.