Andy11548 Posted August 13, 2012 Share Posted August 13, 2012 Hello, this doesn't appear to work with jQuery, I think it's Javascript. Could someone please convert this into jQuery. function ShowSelection() { var textComponent = document.getElementById('topicMessage'); var selectedText; // IE version if (document.selection != undefined) { textComponent.focus(); var sel = document.selection.createRange(); selectedText = sel.text; } // Mozilla version else if (textComponent.selectionStart != undefined) { var startPos = textComponent.selectionStart; var endPos = textComponent.selectionEnd; selectedText = textComponent.value.substring(startPos, endPos) } alert("You selected: " + selectedText); } Thanks, Andy. Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 13, 2012 Share Posted August 13, 2012 jQuery is a library written in Javascript. Regular javascript will still run on your website even if your other code is jQuery. And no, no one is going to convert it for you (if they have any sense). Quote Link to comment Share on other sites More sharing options...
Andy11548 Posted August 13, 2012 Author Share Posted August 13, 2012 I know that... But, how would I use it with jQuery then? Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 13, 2012 Share Posted August 13, 2012 You just use it... What happens? What do you expect? Etc... Quote Link to comment Share on other sites More sharing options...
Andy11548 Posted August 13, 2012 Author Share Posted August 13, 2012 Nevermind, sorted that problem. Now, is there a way, using jQuery I can replace text in a <textarea>? Thanks, Andy. Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 13, 2012 Share Posted August 13, 2012 Yes. You either use val() or html(), I think for a textarea it's the html() one. Quote Link to comment Share on other sites More sharing options...
Andy11548 Posted August 13, 2012 Author Share Posted August 13, 2012 Ok. Do I have a error with this because this doesn't work :/ var textarea=$('textarea'); textarea.html(textarea.html().replace('H',"111111")); Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 13, 2012 Share Posted August 13, 2012 I've never seen replace, and a quick google didn't turn up anything for jQuery. Do you have firebug installed? Quote Link to comment Share on other sites More sharing options...
Andy11548 Posted August 13, 2012 Author Share Posted August 13, 2012 Nope. Do you know a way to use "replace" in jquery? I'm very new to this but would like to use it. Thanks for the help, Andy. Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 13, 2012 Share Posted August 13, 2012 You should install firebug and use it. It's the easiest way to debug your javascript. I have never used replace, but as I said before you can use any javascript WITH jQuery. You don't do anything special to it. The code as it's written looks fine so you need to use a debugging tool to help you. Quote Link to comment Share on other sites More sharing options...
Andy11548 Posted August 13, 2012 Author Share Posted August 13, 2012 Nevermind, I sorted it out after about a hour of trying shit on google. var textarea = $('textarea').val(); textarea = textarea.replace(text, '[b]' + text + '[/b]'); $('textarea').val(textarea); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.