i want to replace that html code with javascript code?
i want to replace all between <p>
tags with a simple word NotFound
<p id='2'>
<?php
foreach ($d as $key=>$value)
{
extract($value);
if($key%4==0)
{
echo "</tr>";
echo"<tr>";
}
include('item.php');
}
echo"</table>";
echo"</div>";
?>
</p>
how can i do that using javaScript??
update: i used that code in the javascript area:
<script type="text/javascript">
window.onload=msg;
开发者_StackOverflow社区 function msg(){
document.getElementById('1').onclick=clickhandlee;
//
}
function clickhandlee(){
var ps = document.getElementsByTagName('p');
for(var i=0, max=ps.length; i<max; i++){
ps[i].innerHTML = "NotFound";
}
}
</script>
and the same previous code in the <body>
tags
<p id='2'>
<?php
foreach ($d as $key=>$value)
{
extract($value);
if($key%4==0)
{
echo "</tr>";
echo"<tr>";
}
include('item.php');
}
echo"</table>";
echo"</div>";
?>
</p>
this is the included php template item.php
<td style='border: 0px none ; margin: 0px; padding: 0px; width: 240px;' align='right' valign='top'>
<div style='margin-bottom: 10px;'>
<table class='topic' border='0' cellpadding='0' cellspacing='0' align='right'>
<tbody>
<tr>
<td style='background: url('style/$style/images/top_background.jpg') no-repeat left center; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous' align='center' height='35'>
<div style='overflow: hidden; width: 230px;'>
<a class='link' href='t<?=$id;?>-<?=$name;?>.html'>
<?=$name;?> </a>
</div>
</td>
</tr>
<tr>
<td align='center' style="height: 197px">
<a href='count-<?=$id;?>;.html'>
<img src='<?=$photo;?>' class='image' border='0' width='220' height='170'/></a>
<div dir='rtl' class='shortdes'><?=$shortdes;?></div>
</td>
</tr>
<tr valign='top'>
<td style='background: url('style/$style/images/footer_background.jpg') no-repeat left center; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; height: 29px;' align='center' height='35'>
<a class='dlink' href='count-<?=$id;?>.html'>
<div class='download' style="height: 17px">
التحميل : <?=$visits;?>
</div></a>
</td>
</tr>
</tbody>
</table>
</div>
</td>
var paragraphs = document.getElementsByTagName('p'),
i = paragraphs.length;
while (i--)
{
paragraphs[i].innerHTML = 'NotFound';
}
Using Javascript:
var ps = document.getElementsByTagName('p');
for(var i=0, max=ps.length; i<max; i++)
ps[i].innerHTML = "NotFound";
Using Javascript
Note comment by user DA - IDs cannot start with a number before HTML 5, so assume that the ID is spelled out (two) instead of the numeral (2) if not using HTML 5.
If it is only for the <p>
tag with id=two:
document.getElementById("two").innerHTML = "NotFound";
If it is for all <p>
tags:
var paragraphs = document.getElementsByTagName("p");
for(var i = 0; i < paragraphs.length; i++) {
paragraphs[i].innerHTML = "NotFound";
}
The key is the innerHTML tag of the DOM elements.
If you're using jquery: $('p').html('NotFound');
精彩评论