Remove empty tag with javascript
July 17, 2008 6:16 PM
Subscribe
I need some help creating some javascript that will remove an empty img tag.
Ok.. So i have the following code in my page. What i am looking to do, is add the ability to remove the empty img tag(<img src="">) by clicking on the Select All button.
If you can show me how to code that, or point me in the right direction (keeping in mind that I have 0 experience with js), I would be greatly appreciative.
Note: Having the script run by clicking on this button isn't really what i want, but the way I see it (which may be, and usually is wrong) seems like the only way to make sure it only runs on the one page i need it to run on. The site consists of many, many includes. The page I need the script on is structured like so... main.html (containing the HEAD and BODY tag) and then page_i_want_script_to_run.html (containing the code I want the script to run on). Is there a way to get the script to run on page_i_want_script_to_run.html automatically on page load, without putting it in the BODY tag of main.html? If so, I would probably go that route.
<!-- Main.html -->
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function copyit(theField) {
var tempval=eval("document."+theField)
tempval.focus()
tempval.select()
therange=tempval.createTextRange()
therange.execCommand("Copy")
}
// End -->
</script>
</HEAD>
<BODY>
<!-- Main.html -->
<!-- page_i_want_script_to_run.html -->
<form name="it">
<div align="center">
<input onclick="copyit('it.select1')" type="button" value="Select All" name="cpy">
<textarea class="code" name="select1" rows="3" cols="25">
<img src="example.jpg">
<img src=""> <!-- help me remove this tag... -->
<img src="example2.jpg">
</textarea>
</div>
</form>
<!-- page_i_want_script_to_run.html -->
posted by B(oYo)BIES to computers & internet (12 comments total)
posted by niles at 6:49 PM on July 17, 2008