0

I have a HTML page where there are many <a onclick="javascript>

What i need to do using Jquery is find the below tag as it is

<a onclick="javascript:OpenNewWindow('/help_options.php?ID=2', 350, 250);" href="javascript:void(0);">

and replace it with

<a onclick="javascript:OpenNewWindow('/help_options.php?ID=2', 600, 500);" href="javascript:void(0);">

Note

1) the values 350 is changes to 600 and 250 is changed to 500 2) there are also many similar tags but i want the code to do Exact find and replace of the above tag.

IS this possible ?

3
  • 1
    Why do you need this? The javascript: label is superfluous in the onclick handler. You should remove it. Commented Jun 3, 2011 at 10:33
  • instead of constants, why not you use variable(s) to control height and width? Commented Jun 3, 2011 at 10:35
  • Could you send the entire page? Commented Jun 3, 2011 at 10:36

2 Answers 2

3

I wouldn't be looking to change the inline onclick Javascript even if I could.

A better approach is to late-bind everything in JavaScript:

$(document).ready(function(){
    $("#MyAnchorID1").click(function(){
        OpenNewWindow('/help_options.php?ID=2', 350, 250);
    });
});

So, when you did want to change the event, you unbind then re-bind. I.e. do something like:

$("#MyAnchorID1").unbind("click").click(function(){
        OpenNewWindow('/help_options.php?ID=2', 600, 250);
});

Of course, that approach just does it for an anchor with a particular id. You could just select 'a' to get all anchors.

A simpler solution might be to define an object literal:

var myDims = {width:350, height:250};

Use that in the function:

 OpenNewWindow('/help_options.php?ID=2', mydims.width, myDims.height);

And just change the values of this when you need:

myDims.width = 600;
Sign up to request clarification or add additional context in comments.

3 Comments

I tried the following at tinyurl.com/3m5dt9t but its not working, nothing is happening on click
Works fine for me. I get a window 1000 in height
its not working on chrome, Ff which browser are you checking ?
0
 $(document).ready(function () {

 $('a').unbind();
 $('a').click(function(){
   OpenNewWindow('/help_options.php?ID=2', 600, 500);
 });
 });

3 Comments

I tried the following at tinyurl.com/3m5dt9t but its not working, nothing is happening on click
you need to run the jquery - put it within a $(document).ready(function () { section as shown above.
That worked but i dont see height nor width is changed ? tinyurl.com/3m5dt9t

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.