0

First, this is probably a duplicate. Just couldn't find any answers that worked for me.

I have a block of elements like this

<a id="folder" href="http://example.com/update.php?dir=%2Fexample%2Fimg">
    <i class="fa fa-folder-o"></i>
    img
</a>

is there any way for jquery (or just js) to find the text inside there? I'd like it to return 'img' when given that setup.

Thanks in advance, Michael

2
  • Go into Developer Tools. Click on the element. At the bottom of the elements window it will display the full selector for the element. Commented May 26, 2016 at 23:42
  • @Barmar did you even read the question? Commented May 26, 2016 at 23:49

3 Answers 3

2

It's simply $("#folder").text()

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

1 Comment

Thanks for the help, I dont know how i didnt see this in the first place lol
0

Let us know what else you want to do with this.

var all = $('a').text();
alert(all);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<a id="folder1" href="http://example.com/update.php?dir=%2Fexample%2Fimg">
    <i class="fa fa-folder-o"></i>
    img
</a>
<a id="folder2" href="http://example.com/update.php?dir=%2Fexample%2Fimg">
    <i class="fa fa-folder-o"></i>
    van
</a>
<a id="folder3" href="http://example.com/update.php?dir=%2Fexample%2Fimg">
    <i class="fa fa-folder-o"></i>
    project
</a>
<a id="folder4" href="http://example.com/update.php?dir=%2Fexample%2Fimg">
    <i class="fa fa-folder-o"></i>
    fun
</a>
<a id="folder5" href="http://example.com/update.php?dir=%2Fexample%2Fimg">
    <i class="fa fa-folder-o"></i>
    picnic
</a>
<a id="folder6" href="http://example.com/update.php?dir=%2Fexample%2Fimg">
    <i class="fa fa-folder-o"></i>
    car
</a>
<a id="folder7" href="http://example.com/update.php?dir=%2Fexample%2Fimg">
    <i class="fa fa-folder-o"></i>
    wagon
</a>

Comments

0

You can use string search() method.

var str = "This is test"; str.search("is")

will return you, first match of the regular expression inside the string, in this case 2.

Checkout

https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/search

1 Comment

You can combine with $(element).text();

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.