[jQuery] unfefined properties (filtering jquery by class)
My goal is to pull out all anchor tags and replace the href value with
a rewritten value (based on original href). However, i am getting
errors indicating that the object or property is undefined when there
are no anchor tags with the given class name (which is why i used
filter...)
I have the following href pattern:
File Library/filename
i need it to be
/newPath?library=File+Library&component=filename
This works as long as at least one anchor tag exists of the
appropriate style class but not when only standard anchor tags are
present.
example:
function rewriteFileHref() {
library = $("a").filter(".changeHrefToWcm").attr("href").split("/")
[0].replace(" ", "+");
id =$("a").filter(".changeHrefToWcm").attr('href').split("/") [1];
$("a").filter(".changeHrefToWcm").attr('href','/NewLocation/
WcmRenderServlet/?library='+library+'&component='+id);
}