1

there have been many questions like this before, but the answer usually involved referencing the element to be outputted to within the script. in my case, elements are created dynamically on load (it's hosted on Tumblr, to be specific), so there's no referable ID for each of the elements I need to output a string to.

is it possible to do this? jQuery can be used if it makes things much simpler. my function takes a string as an input and outputs a string using return.

5
  • 1
    “my function takes a string as an input and outputs a string using return.” What does the string it takes as input represent? Commented Apr 10, 2014 at 21:55
  • @minitech ah, right. it takes Tumblr's {TagsAsClasses} as an input, which is a string containing all the tags relevant specifically to that post. Commented Apr 10, 2014 at 21:58
  • eval all the things! Commented Apr 10, 2014 at 21:58
  • Can you please tell us what the elements you are looking to output too look like ? If you are going to output to them you should know them or know a parent of them. Commented Apr 10, 2014 at 21:59
  • the inside of an <a> tag, which is contained inside <div class="posttext">, which is inside one of many <div class="post"> elements. all I need to do is output a single string to the inside of the <a> tag. Commented Apr 10, 2014 at 22:04

2 Answers 2

2
$('.post .posttext a').html(YourfunctionThatReturnsAString());

This should do it

Sign up to request clarification or add additional context in comments.

Comments

1

$('.post .posttext a') -> this returns an array of a elements.

$('.post').eq(the post number).find('.posttext a') -> replace "the post number" with the number of your post if you want to target something more specific.

You can then call the text("your text") method to set the text.

1 Comment

I've gotten it working like that, this was the most helpful answer!

Your Answer

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.