I have this code
<html>
<head>
<script src="jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="jquery-ui-1.8.20.custom.min.js" type="text/javascript"></script>
<script type = "text/javascript">
function MyFunc(obj,method){
// obj.hide("slow"); // This part is working fine i.e. it is hiding the paragraph
obj + "." + method + "(\"slow\")"; // This is not working
$(function(){
$("#pid1").click(function(){
MyFunc($("#pid1"),"hide");
});
});
</script
</head>
<body>
<p id = "pid1">Test Paragraph</p>
</body>
</html>
i.e I want to pass the parameters to the jquery hide function and form the correct string to call the effect but it is not working as in the code above. Am I missing something ?
You can use square brackets to access the property of an object with a string:
Also note that you had missed the closing curly brace of
MyFunc.What you are currently doing is just producing a string, by concatenating a bunch of strings with an object. It won’t throw an error, but it won’t do anything whatsoever.