next How to find ...">

Jquery find by value

There is a link with titleand nearvalue:

<a href="http://site.com/someid/" title="Use ctrl + >">next</a>

How to find this link and pass its attribute hrefto some variable?

+3
source share
5 answers
var some_variable = $("a:[title='Use ctrl + >']").attr("href")

check jQuery slectors: http://api.jquery.com/category/selectors/

here is a working example: http://jsfiddle.net/SXqVt/

+7
source

You can just use contains , for example

$('a[href*="Use ctrl"]')

or perhaps even more specific with =.

, , , . , , id class. , .find(), .closest() ..

.

+4

, .

- ,

<a href="http://site.com/someid/" title="Use ctrl + >" class="myAnchor">next</a>

jquery

var some_variable = $("a.myAnchor").attr("href")

... , id

<a href="http://site.com/someid/" title="Use ctrl + >" id="myAnchorId">next</a>

jquery

var some_variable = $("#myAnchorId").attr("href")
+2

:contains() , :

alert($('a:contains(next)').attr('href'));

, , "" , jQuery.

+2

meo, :

var hrefValue;
if($("a:[title='Use ctrl + >']").length > 0)
{
    hrefValue = $("a:[title='Use ctrl + >']").attr("href");
}
+1
source

Source: https://habr.com/ru/post/1749940/


All Articles