0

I'm just now getting my feet wet with jQuery (and CSS to an extent) and stumble a lot at simply targeting the right selector. Even if I directly copy and paste the CSS path from Firebug, half the time it won't work.

At the moment, I'm trying to alter the Wibiya toolbar to use my own Wordpress built-in URL shortener instead of theirs, and I figured the easiest way would be to just target it's selector and change it via jQuery.

Here's the code I'm using right now (doesn't work):

$("input#linkUrl").text("testing");

I've tried some other selectors including the full, huge copied Firebug path with no luck as well.

The URL I'm using this on (for anyone wanting to inspect it themselves) is Meanwhile In America, the toolbar is at the very bottom, the item in question is the URL shown where there is the "Copy" button.


UPDATE 10/4/2013 4:22 PM: anyone else have any suggestions? Still not working.

J. Scott Elblein
  • 4,013
  • 15
  • 58
  • 94
  • possible duplicate of [Difference between val() and text()](http://stackoverflow.com/questions/807867/difference-between-val-and-text) – Eric Hotinger Sep 23 '13 at 20:26

2 Answers2

4

You probably want $("input#linkUrl").val("testing"); since your target element is an input.

You can also shorten your selector to #linkUrl if you want to.


As a side node, please don't link to 'live' sites anymore. Instead, provide a simple script or a (not) working jsFiddle.
ComFreek
  • 29,044
  • 18
  • 104
  • 156
  • It's still not having any effect on the target element. Here's the code I currently have: `$(document).ready(function() { $("#linkUrl").val("testing"); });` – J. Scott Elblein Sep 24 '13 at 18:09
  • @GeekDrop.com Can you post your complete script or a snippet which also include this problem in your question, please? – ComFreek Sep 24 '13 at 18:10
  • @ComFreak I'm not sure what you want me to post? It's the Wibiya Toolbar, which is run from an entirely different site (which isn't mine). Other than that I'm just trying to add a small bit of jQuery to alter it's value, as I already posted in the question. – J. Scott Elblein Sep 24 '13 at 18:13
  • @GeekDrop.com I could imagine that the other site already includes another library (e.g. Protoype) which conflicts with jQuery. Can you verify this? Are there any errors in the JS console? – ComFreek Sep 24 '13 at 18:14
  • @ComFreak None that I can see related to Wibiya? – J. Scott Elblein Sep 24 '13 at 18:22
  • @GeekDrop.com Please try replacing `$` by `jQuery`: `jQuery("#linkUrl...`. What about the JS console (F12 in most browsers)? – ComFreek Sep 24 '13 at 18:24
  • @ComFreak Still no luck using jQuery instead of $. No errors either. I've looked w/both Firebug in Firefox, and in the Google Chrome inspector. – J. Scott Elblein Sep 24 '13 at 18:48
3

From jQuery documentation:

The .text() method cannot be used on form inputs or scripts.
To set or get the text value of input or textarea elements, use the .val() method.

$("input#linkUrl").val("testing");
qwertmax
  • 3,120
  • 2
  • 29
  • 42