Thanks. This helped reduce the code but still not perfect.
Here is my present code which works but still I cannot eliminate some
redundant code.
$("a[href$='.doc']:not(a[href^='http']),a[href$='.xls']:not(a
[href^='http']),a[href$='.ppt']:not(a[href^='http']),a[href
$='.pdf']:not(a[href^='http']
Is this what you're looking for?
$("a:not[href^=http]").each(function(){
var ext=$(this).attr("href").match(/\.[^\.]*$/);
if (ext) $(this).after("("+ext.slice
(1)+")");
} );
On May 15, 8:09 am, infoaddicted wrote:
> This calls for a function, where you can hide the gory details. Use a
This calls for a function, where you can hide the gory details. Use a
selector to gather up the "a" elements, and pass that as the argument
to the function.
pseudocode:
var linksToChange = JQuery Selector;
function changeLinks( linksToChange ){
either:
a "for" loop to step through t
OK. I was able to add the text as well as apply special style to it
using the following code.
$("a[href$='.doc']:not(a[href^='http'])").after($('').attr
('class','fileExtension').html(" (" + '.doc' + ") "));
$("a[href$='.docx']:not(a[href^='http'])").after($('').attr
('class','fileExtension').htm
I think it is not clear. Here is my code.
$("a[href$='.doc']").after(" (" + '.doc' + ") ");
$("a[href$='.docx']").after(" (" + '.docx' + ") ");
$("a[href$='.xls']").after(" (" + '.xls' + ") ");
$("a[href$='.xlsx']").after(" (" + '.xlsx' + ") ");
$("a[href$='.ppt']").after(" (" + '.ppt' + ") ");
$
here i modified my code for class adding
var obj = $("a");
for(var i = 0; i < obj.length; i++) {
obj.eq(i).wrap(""
>
> ); // wrap the hyperlink in a span tag
> obj.parent().eq(i).prepend('This is text before the
> hyperlink');
> obj.parent().eq(i).append('This is text after the
> hyperlink');
> }
var obj = $("a");
for(var i = 0; i < obj.length; i++) {
obj.eq(i).wrap(""); // wrap the hyperlink in a span tag
obj.parent().eq(i).prepend("This is text before the hyperlink");
obj.parent().eq(i).append('This is text after the hyperlink');
}
use the above common method and you can furthur change
Also, I would like to apply a specific CSS style to the text being
added.
Here is my CSS.
.fileExtension {
padding-left:0pt;
font-family: Arial, Helvetica, sans-serif;
font-size: 7pt;
font-weight: normal;
color: #354963;
}
On May 14, 1:18 pm, vmrao wrote
Thanks. How about if I want to make it dynamic ? Say, I have several
links on the page with different extensions
(Ex: .doc, .docx, .ppt, .pptx, .pdf, .mpg). Can I accomplish the above
with one statement rather than hard coding what text to append for
each extension ?
On May 14, 12:23 pm, brian
$("a[href$='.pdf']").after(' (pdf)');
On Thu, May 14, 2009 at 11:55 AM, vmrao wrote:
>
> I would like to display file extension along with the file links on a
> web page.
>
> For example, I would like to append (pdf) next to any pdf links.
>
> The following code works to some extent but not as I
10 matches
Mail list logo