-1

I can't get this to display an alert fed as a function argument. I have compared to examples and can't see the problem causing it not to work. I have included my html and JavaScript below, any help in where I'm going wrong will be very gratefully received. Thanks A

HTML:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script src="http://code.jquery.com/jquery.js"></script>
<script src="testjs.js"></script>
</head>
<body>
<div id = "testbed">
<a id = "testlink" href = "#number1">Test click</a>
</div>
</body>
</html>

JavaScript:

$(document).ready(function() {
$.fn.newmodalcontrols = function(modelspec) {
alert(modelspec); 
} // end newmodalcontrols
$('#testlink').click(function() {
 $(this).parent().newmodelcontrols('number1');
}); // end testlink click function
}); // end ready
progrrammer
4,4892 gold badges32 silver badges40 bronze badges
asked May 9, 2013 at 18:15
3
  • Any errors reported in your JavaScript console (F12 in most browsers)? Commented May 9, 2013 at 18:16
  • Yes it says the following...Uncaught TypeError: Object [object Object] has no method 'newmodelcontrols' testjs.js:10 (anonymous function) testjs.js:10 jQuery.event.dispatch jquery.js:3074 elemData.handle Commented May 9, 2013 at 18:19
  • please check that testjs.js is loading properly Commented May 9, 2013 at 18:20

3 Answers 3

1

You just have a typo. Change newmodelcontrols to newmodalcontrols.

JavaScript

$(document).ready(function () {
 $.fn.newmodalcontrols = function (modelspec) {
 alert(modelspec);
 }
 $('#testlink').click(function () {
 $(this).parent().newmodalcontrols('number1');
 });
});

Update: added a jsfiddle example.

answered May 9, 2013 at 18:18
Sign up to request clarification or add additional context in comments.

1 Comment

Haha that took hours of faffing around, feel silly now. Thanks :)
1

You have a typo: newmodalcontrols and newmodelcontrols are not equivalent (note the a/e): corrected the typo, in a JS Fiddle demo:

$(document).ready(function () {
 $.fn.newmodalcontrols = function (modelspec) {
 alert(modelspec);
 } // end newmodalcontrols
 // ^- Should be an 'e'
 $('#testlink').click(function () {
 $(this).parent().newmodelcontrols('number1');
 // ^- Or this should be an 'a'
 }); // end testlink click function
}); // end ready

Incidentally, in Chromium, this would have been shown in the Web Inspector's JavaScript console as:

Uncaught TypeError: Object [object Object] has no method 'newmodelcontrols'

Which should have drawn your attention to the name of the method you were using/defining.

answered May 9, 2013 at 18:18

2 Comments

Thank you for your help, problem solved and lesson learned. A
@Ant: no problem at all, I'm glad to have been of help!
0

You got a typo.

Check out fiddle

http://jsfiddle.net/AUEZJ/

$(document).ready(function () {

$.fn.newmodelcontrols = function (modelspec) {
 alert(modelspec);
}; // end newmodalcontrols
$('#testlink').click(function () {
 $(this).parent().newmodelcontrols('number1');
}); // end testlink click function

}); // end ready

answered May 9, 2013 at 18:23

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.