#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    8
    Rep Power
    0

    How to get the line number of image where alt/title is missing..??


    Hi guys, i am having the javascript function uses regular expression which gives a list of images without alt/title attribute... is there any way to get the line number along with the images
    Alt missing in line no:___ <img src="images/Demo.jpg" border="0">
    My HTML will look like this...
    Code:
    <html>
    <head>
    <title>Untitled Document</title>
    </head>
    <body>
    <table width="600" cellpadding="0" cellspacing="0" border="0">
    <tr>
    	<td width=""><img src="images/Demo.jpg" border="0"></td>
    	<td width=""><img src="images/Demo.jpg" border="0"></td>
    </tr>
    <tr>
    	<td width=""><img src="images/Demo.jpg" border="0"></td>
    	<td width=""><img src="images/Demo.jpg" border="0"></td>
    </tr>
    </table>
    </body>
    </html>
    Below is the function
    Code:
    function AltTitle(aSourceHTML, aResultField) {
        try {
    	regexp = /<img((?:(?!alt)[^<>])*)>/gim;
            var vArray = aSourceHTML.match(regexp);
            var vLinks = vArray.join("\n\n");
            aResultField.value = vLinks;
        } catch (err) {
              alert("No Images Found");
        }
    }
    This will return out put like this
    Code:
    <img src="images/Demo.jpg" border="0">
    
    <img src="images/Demo.jpg" border="0">
    
    <img src="images/Demo.jpg" border="0">
    
    <img src="images/Demo.jpg" border="0">
    How to get the line number of image where alt/title is missing..??
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,238
    Rep Power
    9400
    Split the text up into an array for each line, then loop over that looking for the missing alt attributes.

IMN logo majestic logo threadwatch logo seochat tools logo