Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9054067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:35:20+00:00 2026-06-16T13:35:20+00:00

I am a newbie and I have inherited some nasty jquery code. I am

  • 0

I am a newbie and I have inherited some nasty jquery code. I am trying to find a way so that if an error is found then it replaces the string with another string. This is the original code..

    W.load = function (b) {
    var c, d, g = W.prep; S = ! 0, Q = ! 1, O = x[P], b || _(a.extend(J, a.data(O, e))), ba(l), ba(h, J.onLoad), J.h = J.height? Z(J.height, "y") - M - K: J.innerHeight && Z(J.innerHeight, "y"), J.w = J.width? Z(J.width, "x") - N - L: J.innerWidth && Z(J.innerWidth, "x"), J.mw = J.w, J.mh = J.h, J.maxWidth &&(J.mw = Z(J.maxWidth, "x") - N - L, J.mw = J.w && J.w < J.mw? J.w: J.mw), J.maxHeight &&(J.mh = Z(J.maxHeight, "y") - M - K, J.mh = J.h && J.h < J.mh? J.h: J.mh), c = J.href, V = setTimeout(function () {
        B.show()
    },
    100), J.inline?(Y().hide().insertBefore(a(c)[0]).one(l, function () {
        a(this).replaceWith(z.children())
    }), g(a(c))): J.iframe? g(" "): J.html? g(J.html): $(c)?(a(Q = new Image).addClass(f + "Photo").error(function () {
        //J.title = ! 1, g(Y("Error").text("This image could not be loaded"))
        J.title = ! 1, a(this).href.replace('http://www.old.com','http://www.new.com');
    }).load(function () {
        var a; Q.onload = null, J.scalePhotos &&(d = function () {
            Q.height -= Q.height * a, Q.width -= Q.width * a
        },
        J.mw && Q.width > J.mw &&(a =(Q.width - J.mw) / Q.width, d()), J.mh && Q.height > J.mh &&(a =(Q.height - J.mh) / Q.height, d())), J.h &&(Q.style.marginTop = Math.max(J.h - Q.height, 0) / 2 + "px"), x[1] &&(P < x.length - 1 || J.loop) &&(Q.style.cursor = "pointer", Q.onclick = function () {
            W.next()
        }), m &&(Q.style.msInterpolationMode = "bicubic"), setTimeout(function () {
            g(Q)
        },

I have changed the code to this..

J.title = ! 1, a(this).href.replace('http://www.old.com','http://www.new.com');

But its not working. Ggr! Any help would be greatly appriciated. 🙂

UPDATE*

The code above is the complete code for the section I am working in..

UPDATE #2

This answer works but I need to do…

a(this).attr('src', function(i, current){ 
 if ( i === 'http://www.old.com'){
 return current.replace('http://www.old.com','http://www.new.com');
 }
 else if ( i === 'http://www.older.com'){
 return current.replace('http://www.older.com','http://www.new.com');
}
 else ();
 })

This isn’t working!! Help!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T13:35:21+00:00Added an answer on June 16, 2026 at 1:35 pm

    Try

    this.href.replace('http://old.com/' , 'http://new.com/');
    

    If you want to change the actual attribute to a new one on the current element then

    this.href = this.href.replace('http://old.com/' , 'http://new.com/');
    

    If you are inside a handler that refers to an <a> element then this refers to that object and you do not need to make a jquery object out of it, to access its properties.. so this.href will refer directly to the href property of the link.


    Disclaimer: That is obfusated/encoded script and you should better find the original from which this was produced.. This code makes no sense and our suggestion are really in the blind..

    From a first look it seems the this is an image and not a link, so if you want to show a new image then you would need to change the src attribute and not the href which does not exist on images..

    a(this).attr('src', function(i, current){ return current.replace('http://www.old.com','http://www.new.com');})
    

    But you should also do a console.log(a.fn.jquery) in there to make sure that a is a reference to jQuery

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm an asp.net newbie. I have inherited a base of asp.net mvc code and
I am a ruby newbie and have been trying Sinatra for quite some time
Newbie Python question. I have a class that inherits from several classes, and some
I have some inherited code for opening IE, this is short version : procedure
I'm a newbie in Spring Batch. I have inherited a batch process implemented with
I'm a complete C# newbie and have been trying to crack this for a
I'm brand new to SQL Server 2008, and have some newbie questions about the
I'm a Drupal newbie plus I don't have much experience updating code, styles, and
SharePoint newbie here. I have a web part that is attached to SharePoint's edit
I am a C# newbie and have a class that needs to pass row

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.