Jump to content

Help with a jQuery plugin?


eiranix
 Share

Recommended Posts

I'm not that familiar with jQuery so I was wondering if someone could point out what I'm doingn wrong?

 

Attemping to use the jQuery Textrange plugin found here: https://github.com/dwieeb/jquery-textrange

 

When I try to simply use the replace feature:

function replaceMe() {  $('input[name="fred"]').textrange('replace', 'apples');};

I am getting an error in the console saying "TypeError: invalid 'in' operand this[0] jquery-textrange.js:192"

 

Any guidance is appreciated...

Link to comment
Share on other sites

The reason I thought it was my problem is that there is an example page that works just fine with no errors. The example page and my basic test page are local and using the same js links.

 

I was using the console in firefox so maybe that makes a difference where the line number is concerned?

 

For more info, this is my test page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><script type="text/javascript" src="jquery-1.11.1.min.js"></script><script type="text/javascript" src="jquery-textrange.js"></script><script>function replaceMe() {  $('input[name="fred"]').textrange('replace', 'apples');};</script></head><body><textarea name="fred" id="fred" ></textarea><input style="height:40px;" type="button" id="rep" name="rep" value="Click to Replace" onclick="replaceMe();"/></body></html>
Link to comment
Share on other sites

Ok so I've discovered how to make it work :)

 

The Methods on the site say to write:

$('input[name="example"]').textrange('replace', 'some text');
But I found the demo did it slightly differently, so the way it works is:
$('#fred').textrange('replace', 'apples');
Link to comment
Share on other sites

 

Ok so I've discovered how to make it work :)

 

The Methods on the site say to write:

$('input[name="example"]').textrange('replace', 'some text');
But I found the demo did it slightly differently, so the way it works is:
$('#fred').textrange('replace', 'apples');

 

 

It would have worked if your jQuery selector matched your DOM, so instead of "example", you should have been using "fred" for value of name

$('input[name="fred"]').textrange('replace', 'some text');
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...