X
X
XenK2016-08-02 09:07:06
JavaScript
XenK, 2016-08-02 09:07:06

'indexOf' of undefined?

I use this expression:

if ($('div a').attr('data-content').indexOf('warning') + 1) {
    ...

But in the console, the following error occurs:
Uncaught TypeError: Cannot read property 'indexOf' of undefined


HTML:
<div>
    <a data-toggle="popover" data-html="true" title="Блок #1" data-content="Загрузка..."
       role="button" data-placement="bottom"></a>
</div>

When pasted into the data-content attribute, the resulting HTML is:
<div>
    <a data-toggle="popover" data-html="true" title="Блок #1" data-content="<div class="info">info</div><div class="warning">info</div>"
       role="button" data-placement="bottom"></a>
</div>


How to fix it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
X
XenK, 2016-08-02
@XenK

I solved the problem with the String function for the inserted string.

D
Dmitry Kovalsky, 2016-08-02
@dmitryKovalskiy

1) for data-attributes there is a data() method.
2) Open the console and execute the code
Make sure that it returns. data attributes are case sensitive, e.g.
3) Explain the purpose of this -

<a data-toggle="popover" data-html="true" title="Блок #1" data-content="<div class="info">info</div><div class="warning">info</div>"
       role="button" data-placement="bottom"></a>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question