jquery datatable cannot change image on hidden columns

292
January 02, 2017, at 10:38 PM

I am using jquery datatable responsive. When i have a big monitor all the cells are showed and I can change src of image using javascript easly, but when i use a monitor that resize my datatable and hide some cloulmns if i change the src value of an image on a hidden columns (showed by clicking on plus icon) the image dont change, neither the src attribute. Here is an example of hidden columns

Follow the datatable init:

$(function() {
        table = $('#DT_ADS').
        DataTable({
            "language": {
                "url": "plugins/datatables/localizations/italian.json"
            },
            "paging": true,
            "lengthChange": true,
            "searching": true,
            "ordering": true,
            "info": true,
            "autoWidth": false,
            "bDeferRender": true,
            "lengthMenu": [5, 10, 15],
            "pageLength": 5,
            "order": [
                [8, "desc"]
            ],
            "columnDefs": [
                { targets: "_all",className: "ALING_CENTER"}
              ],
            "sAjaxSource": "ajax/get_ads_datatable.ajax.php",
        });
    });

Can someone help me?

EDIT: The image is a switch, when i click on it I call a function that perform an ajax call and then edit the src of image to display the correct image inherent in the new changed value.

NOTE: If i send the element to the function

<img id="my_img_1" src="path/of/image.jpg" onclick="changeSrc(this)" /> 
function changeSrc(elem){
elem.src="path/of/image_2.jpg";
}

it work also on responsive mode and it change the image succesfully, but i don't undestand why if i try to change the src using

document.getElementById("my_img_1").src="path/of/image_2.jpg";

it does not work; seems that the datatable create 2 element of my image and using getElementById i can access only to first that are not displayed

Answer 1

I think i can help but i need to see more code :D

READ ALSO
How in JavaScript can I access a property of a DOM element, which is surrounded in angular brackets &lt; &hellip; &gt;?

How in JavaScript can I access a property of a DOM element, which is surrounded in angular brackets < … >?

I'm developing a site which requests data from a third-party, so I use jQuery's $ajax and in order to avoid blocking the asynchronous transaction I've applied a promise and created a Promise object

292
Need to adjust a field in text editor after i type something

Need to adjust a field in text editor after i type something

So i'm making a Text Editor,but what i need to do is

367
How to store the index for each row in a html table into mysql database using php?

How to store the index for each row in a html table into mysql database using php?

I have html table contains date already stored in database , and i want to store the index of each row of this table in database using php , to order the table data via index

199
Append dynamic vue component after specific element

Append dynamic vue component after specific element

I want to add component in random position (not random actually, based on some logic) based on click of other elements

744